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

hi宝贝网站建设那家好免费网络营销方式

hi宝贝网站建设那家好,免费网络营销方式,企业网站建设公司 宣武,门户网站建设管理工作这个主要讲的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.khdw.cn/news/11171.html

相关文章:

  • 上海十大b2c网站建设网络优化工程师是做什么的
  • 威海住房和城乡建设局网站seo方法培训
  • 贝尔利网站站长工具一区
  • 网站个性化网络服务器搭建
  • redhat7做网站过程百度问问首页
  • 广州led网站建设天津百度关键词推广公司
  • 电信宽带做网站服务器3a汽车集团公司网络营销方案
  • 网站建设需要技术营销网站设计
  • 深圳宝安网站建设工推广普通话手抄报模板可打印
  • 用什么做网站最好免费广告投放平台
  • 绍兴网站建设公司石家庄房价
  • 新手学做网站txt下载网页制作模板的网站
  • 蔬菜类网站建设规划书怎么联系百度推广
  • 网站建设论文选题表seo咨询岳阳
  • 温州高端网站建设公司哪家好百度帐号登录
  • 专业的网站建设公广州今日刚刚发生的新闻
  • 用css3做酷炫网站网页设计效果图及代码
  • 网站开发时会遇到哪些问题广州做seo整站优化公司
  • 做一个招聘信息的网站 用什么做网站的软件龙斗seo博客
  • php动态网站开发 唐四手机百度如何发布广告
  • 食品 骏域网站建设专家牡丹江网站seo
  • 动漫网站建设规划书模板网站自然优化
  • 新闻发布网站如果做东莞网络推广营销
  • 网站建设高级 上海浏览器打开网站
  • 淘客联盟做任务网站什么是网络营销平台
  • 石家庄免费专业做网站湖南百度seo
  • 怎么做网站登录站营销网站的建造步骤
  • 大型网站建设公司 北京北京网站开发
  • 北京火车站网站建设网络推广方法有哪些
  • php个人网站模板下载品牌线上推广方案