在使用红米手机拍摄照片时,出现闪退的情况。

调用系统相机拍摄照片,使用FileProvider.getUriForFile传入Uri时,报异常

java.lang.SecurityException: Permission Denial: writing android.support.v4.content.FileProvider uri ...

此时需要调用

grantUriPermission(String toPackage, Uri uri, int modeFlags)

授予Uri的访问权限

具体代码如下

    try {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
tempFile = File.createTempFile("head", null, StorageUtils.getImageDir(context));
Uri imgUri = FileProvider.getUriForFile(context,
context.getPackageName() + ".FileProvider", tempFile);
List resInfoList = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (resInfoList.size() == 0) {
DadaToast.showToast(context, "没有合适的相机应用程序");
return;
}
Iterator resInfoIterator = resInfoList.iterator();
while (resInfoIterator.hasNext()) {
ResolveInfo resolveInfo = (ResolveInfo) resInfoIterator.next();
String packageName = resolveInfo.activityInfo.packageName;
grantUriPermission(packageName, imgUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
}
intent.putExtra(MediaStore.EXTRA_OUTPUT, imgUri);
startActivityForResult(intent, REQUEST_TAKE); } catch (ActivityNotFoundException e1) {
DadaToast.showToast(context, "没有合适的相机应用程序");
e1.printStackTrace();
} catch (IOException e2) {
DadaToast.showToast("创建文件失败");
e2.printStackTrace();
}

java.lang.SecurityException: Permission Denial: writing android.support.v4.content.FileProvider uri的更多相关文章

  1. java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media/20 from pid=711, uid=10074 requires android.permission.READ_

    java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider ur ...

  2. Android java.lang.SecurityException: Permission Denial

    报错: java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE ...

  3. 关于Android 8.0java.lang.SecurityException: Permission Denial错误的解决方法

    背景 当我在Android 7.0及以下手机运行启动页,进行Activity跳转的时候,完美跳转到对应的目标Activity. 但当在Android 8.0及以上手机进行Activity跳转时,会爆如 ...

  4. android 报错: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/animation/AnimatorCompatHelper;

    在使用SmartRefreshLayout时,报 java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/a ...

  5. java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/animation/AnimatorCompatHelper

    在开发过程中,有的时候引入了多个三方库.在调用的时候会出现版本对应不上的原因.就会出现如标题的异常. 原因 经过查找,项目中使用的RecycleView类,进入类里面发现AnimatorCompatH ...

  6. java.lang.SecurityException: Permission denied (missing INTERNET permission?) 解决

    Android app里试图用HttpUrlConnection获取网络连接,忘记在AndroidManifest清单文件里声明需要用到Internet的权限,运行时报此错误. 解决方法 在Andro ...

  7. java.lang.SecurityException: Permission denied (missing INTERNET permission?)

    ndroid app里试图用HttpUrlConnection获取网络连接,忘记在AndroidManifest清单文件里声明需要用到Internet的权限,运行时报此错误. 解决方法 在Androi ...

  8. 记录一个调了半天的问题:java.lang.SecurityException: Permission denied (missing INTERNET permission?)

    Move the <uses-permission> elements outside of <application>. They need to be immediate ...

  9. app:transformClassesWithJarMergingForDebug uplicate entry: android/support/v4/app/BackStackState$1.class

    .Execution failed for task ':app:transformClassesWithJarMergingForDebug'.> com.android.build.api. ...

随机推荐

  1. jQuery跨域调用Web API

    我曾经发表了一篇关于如何开发Web API的博客,链接地址:http://www.cnblogs.com/guwei4037/p/3603818.html.有朋友说开发是会开发了,但不知道怎么调用啊? ...

  2. vs2017企业版本安装和序列号

    离线包大概下载为19G,可以选择的选择项很多,很不错,安装如下: 安装完成 启动效果 SharePoint插件自带了 离线包(19G) Visual Studio 2017(VS2017) 企业版En ...

  3. 基础知识——CentOS7操作系统的安装图文教程

    学习了很久的Linux操作系统,也看了不少的资料,对于操作系统的安装,相对来说都在不断的改进,安装的难度也在不断的降低,操作步骤也变得非常的简单了. 有很多CentOS系统的安装教程,但是比较不全面或 ...

  4. C#调用VB进行简繁转换

    首先在C#项目中引用Microsoft.VisualBasic.dll,版本自己选择合适的 然后在项目中添加引用:using Microsoft.VisualBasic; 转换: 转为繁体: outp ...

  5. MSSQL SQL Server代理 作业 设置(调用存储过程)

    1.新建作业名 “生成分区文件及文件组“ 2.新建  步骤  名 “CreatePartTable” 步骤名:CreatePartTable 类型:Transact-SQL 脚本(T-SQL) 数据库 ...

  6. 洛谷P1040 加分二叉树【记忆化搜索】

    题目链接:https://www.luogu.org/problemnew/show/P1040 题意: 某一个二叉树的中序遍历是1~n,每个节点有一个分数(正整数). 二叉树的分数是左子树分数乘右子 ...

  7. ubuntu16.04下安装opencv3.4.1及其扩展模块

    1.源文件下载 opencv-3.4.1.tar.gz(https://github.com/opencv/opencv/releases) opencv_contrib-3.4.1.tar.gz(h ...

  8. [No0000F4]C# 枚举(Enum)

    枚举是一组命名整型常量.枚举类型是使用 enum 关键字声明的. C# 枚举是值数据类型.换句话说,枚举包含自己的值,且不能继承或传递继承. 声明 enum 变量 声明枚举的一般语法: enum &l ...

  9. bilibili的直播第三方IJKMediaFramework.framework下载打包使用教程

    参考和引用的地址: http://www.code4app.com/thread-8941-1-1.html http://blog.csdn.net/cccallen/article/details ...

  10. 网络层block,delegate之优劣分析

    正常情况下, block 缺点: 1.block很难追踪,难以维护 2.block会延长先关对象的生命周期 block会给内部所有的对象引用计数+1, 一方面会带来潜在的循环引用(retain cyc ...