Android 7.0 自动安装APK及拍照崩溃问题
来源:互联网 发布:sybase数据库有哪些 编辑:程序博客网 时间:2024/06/14 01:41
解决方法
1,在AndroidManifest中添加
<provider android:name="android.support.v4.content.FileProvider" android:authorities="${applicationId}.fileProvider" android:grantUriPermissions="true" android:exported="false"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> </provider>
2,在res目录下新建xml文件夹,添加file_paths.xml文件,内容如下:
<?xml version="1.0" encoding="utf-8"?> <paths> <external-path path="Android/data/com.heyikun.hehemall/" name="files_root" /> <external-path path="." name="external_storage_root" /> <external-path name="external_storage_root" path="."/> <files-path name="files" path="."/> </paths>
3,安装APP
private void installApk(File file) { Intent install = new Intent(Intent.ACTION_VIEW); //判断是否是AndroidN以及更高的版本 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { install.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); Uri contentUri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".fileProvider", file); install.setDataAndType(contentUri, "application/vnd.android.package-archive"); } else { install.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } mContext.startActivity(install); }
4,拍照
public Intent dispatchTakePictureIntent() throws IOException { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(mContext.getPackageManager()) != null) { File file = createImageFile(); Uri photoFile; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { String authority = mContext.getApplicationInfo().packageName + ".fileProvider"; photoFile = FileProvider.getUriForFile(this.mContext.getApplicationContext(), authority, file); } else { photoFile = Uri.fromFile(file); } if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoFile); } } return takePictureIntent; } private void openCamera() { try { Intent intent = captureManager.dispatchTakePictureIntent(); startActivityForResult(intent, ImageCaptureManager.REQUEST_TAKE_PHOTO); } catch (IOException e) { e.printStackTrace(); } catch (ActivityNotFoundException e) { // TODO No Activity Found to handle Intent e.printStackTrace(); } }
阅读全文
0 0
- Android 7.0 自动安装APK及拍照崩溃问题
- android 7.0安装APK崩溃
- 关于android 7.0调用相机拍照崩溃问题
- 关于android 7.0调用相机拍照崩溃问题
- Android APK自动安装
- android 7.0apk安装问题
- Android 7.0下载Apk后自动安装
- Android 7.0下载Apk后自动安装
- android 7.0拍照崩溃适配
- Android 版本更新下载自动安装APK,并解决Android6.0,7.0安装失败的问题
- android 6.0以上系统apk自动安装失败问题
- Android APK 文件自动安装
- android 7.0拍照问题
- Android 7.0之后安装APK,拍照 出现FileUriExposedException,多个provider配置
- Android N 7.0 上安装apk问题
- android安装及卸载apk
- android 7.0 apk版本更新,下载之后自动安装
- Android APK 安装/更新问题
- webuploader自己选择上传指定的文件
- 欢迎使用CSDN-markdown编辑器
- Centos7+可视界面+Apache+php+mysql环境搭建,踩了坑过来的
- 面试心得 --- GridSum(国双)算法工程师
- Smoke test,Sanity test,Regression test之间的区别
- Android 7.0 自动安装APK及拍照崩溃问题
- Caffe2
- Redis 安装以及基本使用
- 进阶4_更深入的了解AdapterView
- android 全局无标题透明dialog
- Android自定义RatingBar
- Spring实战4之SpringMVC高级篇
- Opencv HOG特征函数简介
- windows下vue-cli及webpack 构建网站及 路由vue-router的使用