当前位置: 首页 > news >正文

好看欧美视频网站模板下载 迅雷下载地址网站建设工作进度计划表

好看欧美视频网站模板下载 迅雷下载地址,网站建设工作进度计划表,海口软件开发公司,展示用网站这个主要讲的InputStream去保存。 如果需要BItmap与InputStream相互转换可以参考 Android Bitmap、InputStream、Drawable、byte[]、Base64之间的转换关系 保存图片我们需要考虑系统版本,Q前后还是不一样的。 /*** 保存图片* param context 上下文* param inputS…

这个主要讲的InputStream去保存。
如果需要BItmap与InputStream相互转换可以参考

Android Bitmap、InputStream、Drawable、byte[]、Base64之间的转换关系

保存图片我们需要考虑系统版本,Q前后还是不一样的。

  /*** 保存图片* @param context  上下文* @param inputStream 流* @param suffixName  后缀名(.png  .jpg)* @return* @throws IOException*/public static String saveImageFromInput(Context context, InputStream inputStream, String suffixName) throws IOException {if (androidQ()) {Uri uri = saveImageFromInputByAndroidQMedia(context, inputStream, suffixName);String imagePathByUri = getImagePathByUri(context, uri);return imagePathByUri;} else {String imagePtah = createFilePath(context, suffixName,randomName() + suffixName).getAbsolutePath();saveImageFromInputByAndroid(context, inputStream, imagePtah);return imagePtah;}}/*** 保存媒体库(AndroidQ)* @param context* @param inputStream* @param suffixName* @return*/private static Uri saveImageFromInputByAndroidQMedia(Context context, InputStream inputStream, String suffixName) {BufferedInputStream bis = null;OutputStream outputStream = null;BufferedOutputStream bos = null;Uri uri = null;try {bis = new BufferedInputStream(inputStream);uri = getImageUriByMediaStore(context, suffixName);if (uri != null) {outputStream = context.getContentResolver().openOutputStream(uri);if (outputStream != null) {bos = new BufferedOutputStream(outputStream);byte[] buf = new byte[102400];int bytes = bis.read(buf);while (bytes >= 0) {bos.write(buf, 0, bytes);bos.flush();bytes = bis.read(buf);}}}} catch (IOException e) {e.printStackTrace();} finally {closeSilently(bis);closeSilently(bos);closeSilently(outputStream);return uri;}}/*** 保存本地* @param context* @param inputStream* @param imagePath*/private static void saveImageFromInputByAndroid(Context context, InputStream inputStream, String imagePath) {BufferedInputStream bis = null;OutputStream outputStream = null;BufferedOutputStream bos = null;try {bis = new BufferedInputStream(inputStream);outputStream = new FileOutputStream(imagePath);if (outputStream != null) {bos = new BufferedOutputStream(outputStream);byte[] buf = new byte[102400];int bytes = bis.read(buf);while (bytes >= 0) {bos.write(buf, 0, bytes);bos.flush();bytes = bis.read(buf);}}} catch (IOException e) {e.printStackTrace();} finally {closeSilently(bis);closeSilently(bos);closeSilently(outputStream);}}public static Uri getImageUriByMediaStore(Context context, String suffixName) throws IOException {Uri uri;if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {// 7.0之前获取uri方式uri = Uri.fromFile(createFilePath(context, "image", randomName() + suffixName));} else if (androidQ()) {ContentValues contentValues = new ContentValues();contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, randomName() + suffixName);contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "image/*");contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_DCIM);uri = context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues);} else {//7.0之后获取uri方式uri = FileProvider.getUriForFile(context, FileAppProvider.getProviderName(context), createFilePath(context, "image", randomName() + suffixName));}return uri;}/*** 创建文件路径* @param context* @param folderName* @param fileName* @return* @throws IOException*/private static File createFilePath(Context context, String folderName, String fileName) throws IOException {String path;if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/app/" + folderName + "/" + fileName;} else {path = context.getCacheDir().getAbsolutePath() + "/app/" + folderName + "/" + fileName;}return createFile(new File(path));}/*** 创建文件* @param imageFile* @return* @throws IOException*/private static File createFile(File imageFile) throws IOException {if (!imageFile.getParentFile().exists()) {imageFile.getParentFile().mkdirs();}if (imageFile.exists()) {imageFile.delete();}if (!imageFile.exists()) {imageFile.createNewFile();}return imageFile;}/*** 获取uri 对应 path* @param context* @param uri* @return*/public static String getImagePathByUri(Context context, Uri uri) {String imagePath = null;if (context != null && uri != null) {String[] proj = {MediaStore.Images.Media.DATA};Cursor cursor = context.getContentResolver().query(uri, proj, null, null, null);if (cursor.moveToFirst()) {int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);imagePath = cursor.getString(column_index);}cursor.close();}return imagePath;}public static void closeSilently(Closeable c) {if (c == null) return;try {c.close();} catch (Throwable t) {// Do nothing}}public static boolean androidQ() {return Build.VERSION.SDK_INT > Build.VERSION_CODES.Q;}/*** 生成随机名称** @return*/public static String randomName() {return System.currentTimeMillis() + "_" + new Random().nextInt();}

FileAppProvider
public class FileAppProvider extends FileProvider {public static String getProviderName(Context context) {return context.getPackageName() + ".app.file.app.provider";}
}

file_app_provider.xml

<?xml version="1.0" encoding="utf-8"?>
<!--Copyright 2017 Yan Zhenjie.Licensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.
-->
<paths><external-pathname="external_path"path="."/><external-files-pathname="external_files_path"path="."/><external-cache-pathname="external_cache_path"path="."/><files-pathname="file_path"path="."/><cache-pathname="cache_path"path="."/></paths>

清单文件添加:

  <providerandroid:name="com.app.file.provider.FileZqcfProvider"android:authorities="${applicationId}.app.file.app.provider"android:exported="false"android:grantUriPermissions="true"android:multiprocess="true"><meta-dataandroid:name="android.support.FILE_PROVIDER_PATHS"android:resource="@xml/file_app_provider" /></provider>

http://www.yayakq.cn/news/442270/

相关文章:

  • wordpress站点地址和网站开发属于哪一类
  • 前端课程网站wordpress 镜像
  • 微网站方案网站内部资源推广怎么做
  • 微信公众号平台官网网址seo站长工具推广平台
  • 网站界面切片做程序玉溪网站制作公司
  • 网站建设优化服务公司2023年房地产彻底结束
  • 网站 php .net用asp.net做网站
  • 网站上做404页面怎样做加急网站备案
  • 做网站内存最小源码重庆九龙坡营销型网站建设公司哪家专业
  • 做平面设计必看的网站做logo用什么网站
  • 运动猿app 网站开发请求做女朋友的网站源码
  • wordpress菜单跳出百度seo最新算法
  • 政务公开 加强门户网站建设wordpress附件数据库
  • 中网站建设如何设置wordpress的语言
  • 洛阳免费网站建设怎么建设大淘客网站
  • 上海网站设计大概要多少钱适合 wordpress 图标
  • 宁波市建设工程检测协会网站10_10_设计公司网站设计
  • 东莞网站建没wordpress做管理系统
  • 南京建站平台网站打不开 ...
  • 网站模版源码市场部网页设计西安
  • 做网站需要会什么软件软件开发专业学校
  • 设计专业新手网站app界面设计总结
  • 网站与网站做外链好吗有没有教做帽子的网站
  • 做私活一个网站大概多少钱中国做跨境电商出口的网站
  • 具有价值的专业网站建设平台做网站前端需要编程基础吗
  • 浙江广发建设有限公司网站江门住房与城乡建设局官方网站
  • 建网站企业百姓畅言六安杂谈
  • 保险网站导航wordpress关键词调用
  • 自己模板做网站靖州建设局网站
  • 做网站在哪个地方买空间frontpage可以做网站吗