SecurityException异常:权限拒绝:阅读(仅在仿真器) [英] SecurityException: Permission Denial: reading (only on emulator)

查看:356
本文介绍了SecurityException异常:权限拒绝:阅读(仅在仿真器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个活动,在我的应用程序,调用MainActivity ImagePicker,其中有一个GridView在手机的画廊,在这里我用一个ContentResolver的要得到光标铺设的所有图像。

它的工作我的手机上很好,当我测试,但每一次瞬间坠毁模拟器。

下面是错误日志:


  

java.lang.SecurityException异常:权限拒绝:阅读com.android.providers.media.MediaProvider URI内容://媒体/外部/图像/从PID = 5934的媒体,UID = 10060需要android.permission.READ_EXTERNAL_STORAG​​E,或grantUriPermission()


我有写的权限清单中,如下图所示:

 <使用许可权的android:NAME =android.permission.READ_EXTERNAL_STORAG​​E/>
<使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAG​​E/><应用
    机器人:allowBackup =真
    机器人:图标=@的mipmap / ic_launcher
    机器人:标签=@字符串/ APP_NAME
    机器人:主题=@风格/ AppTheme>
    <活动
        机器人:名字=。MainActivity
        机器人:标签=@字符串/ APP_NAME
        机器人:出口=真正的>
        &所述;意图滤光器>
            <作用机器人:名字=android.intent.action.MAIN/>            <类机器人:名字=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>
    < /活性GT;    <活动机器人:ImagePickerNAME = />
< /用途>


解决方案

什么版本的Andr​​oid模拟器?而你跟SDK编译23?
如果你的模拟器是棉花糖,你需要明确检查在运行时的权限。这是因为新的权限模型。

检查出文档的更多信息权限:<一href=\"https://developer.android.com/$p$pview/features/runtime-permissions.html\">https://developer.android.com/$p$pview/features/runtime-permissions.html

I have two activities in my app, MainActivity calls ImagePicker, which has a GridView laying out all the images in the phone gallery, where I use a ContentResolver to get the cursor.

It worked fine on my phone when I tested it but crashed every time instantly on emulator.

Here's the error log:

java.lang.SecurityException: Permission Denial:reading com.android.providers.media.MediaProvider uri content://media/external/images/media from pid=5934, uid=10060 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()

I do have permission written in manifest, as shown below:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name=".ImagePicker" />
</application>

解决方案

What version of android is your emulator? And are you compiling with SDK 23? If your emulator is Marshmallow, you need to explicitly check for the permission at runtime. This is due to the new permissions model.

Check out the docs on permissions for more info: https://developer.android.com/preview/features/runtime-permissions.html

这篇关于SecurityException异常:权限拒绝:阅读(仅在仿真器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆