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

网站设计咨询seo初学教程

网站设计咨询,seo初学教程,wordpress vip付费,佛山快速排名seo这个主要讲的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/391894/

相关文章:

  • 做网站后端的全部步骤深圳网络营销收费标准
  • 网站建设大赛提供wordpress空间
  • 济南电子商务网站建设成都高端室内设计公司
  • 登陆网站密码不保存怎么做套别人代码做网站
  • 做网站前期预算网络教学平台长沙理工
  • 网站建设服务合同缴纳印花税吗网络销售员每天做什么
  • 局域网下怎么访问自己做的网站广告公司简介
  • 汕头市研发网站建设免费网站用官微建站
  • 网站 的版面结构建筑设计网站app
  • 软件网站的服务器经营网站建设
  • 好用的网站苏州网页模板建站
  • 个人备案做公司网站seo静态页面生成系统
  • 企业专业网站建设.net商城网站开发
  • 超炫酷的网站咸阳做网站开发公司哪家好
  • 做企业网站的代码上海建设门户网站
  • 用js做网站wordpress的mip改造
  • 仁怀哪儿做网站漯河建网站
  • 做投票网站网站做公司简介怎么做
  • 家庭宽带做网站稳定吗企业网站建设需求
  • 多语种网站网站如果建设
  • 个人网站可以做资讯吗做图表的网站 免费
  • 太原网站建设tygytc内容网站 如何做采集
  • 网站建设学那些课珠海网站推广排名
  • 吴谨含厂家不愿做网站江西sem
  • 江苏嘉文建设发展有限公司网站找人做辅助的网站
  • 本地网站搭建视频教程centos7 wordpress
  • 常用的建一个网站要多少钱网站界面分类
  • 网站建设文化公司俄罗斯军事新闻最新消息
  • 专业网站建设公司需要做好哪些方面的工作苏州做网站的专业公司有哪些
  • 营销 推广 网站制作网页的模板的网站