Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
459 views
in Technique[技术] by (71.8m points)

android - SecurityException: Permission Denial: reading (only on emulator)

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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/training/permissions/index.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...