简体   繁体   English

Android Studio权限拒绝

[英]Android Studio Permission Denial

I am not sure if this is the right place to ask this question but I can't find help anywhere. 我不确定这是否是问这个问题的合适地点,但我在任何地方都找不到帮助。 I'm trying to get this application to work but I've run into some errors. 我正在尝试使该应用程序正常工作,但是遇到了一些错误。

Clicking "Open gallery" button immediately crashes whole app with this error: 点击“打开画廊”按钮会立即使整个应用程序崩溃,并显示以下错误:

    FATAL EXCEPTION: main
Process: com.niel.galleryphotoapp, PID: 3691
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.niel.galleryphotoapp/com.niel.galleryphotoapp.HomeFragmentActivity}: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media from pid=3691, uid=10086 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
 at android.app.ActivityThread.-wrap12(ActivityThread.java)
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
 at android.os.Handler.dispatchMessage(Handler.java:102)
 at android.os.Looper.loop(Looper.java:154)
 at android.app.ActivityThread.main(ActivityThread.java:6119)
 at java.lang.reflect.Method.invoke(Native Method)
 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
    Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media from pid=3691, uid=10086 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
at android.os.Parcel.readException(Parcel.java:1684)
 at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:421)
at android.content.ContentResolver.query(ContentResolver.java:532)
at android.content.ContentResolver.query(ContentResolver.java:474)
at com.niel.galleryphotoapp.DeviceImageManager.getPhoneAlbums(DeviceImageManager.java:34)
at com.niel.galleryphotoapp.HomeFragmentActivity.onCreate(HomeFragmentActivity.java:80)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6119) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 

I don't know why it is happening, I checked the manifest and it seems the required permissions are there. 我不知道为什么会发生这种情况,我检查了清单,似乎那里有所需的权限。

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

I'm using Android Studio 2.3.3 + Nexus 4 API 25 emulator. 我正在使用Android Studio 2.3.3 + Nexus 4 API 25仿真器。

Although you have included permissions in your manifest, you also need to request runtime permissions as well. 尽管清单中已包含权限,但您还需要请求运行时权限。 Everything you need to know is here: 您需要了解的所有信息都在这里:

https://developer.android.com/training/permissions/requesting.html https://developer.android.com/training/permissions/requesting.html

As cjnash said, you need to ask for runtime permissions as well. 正如cjnash所说,您还需要询问运行时权限。 If you need a quick way just to try it, you can go in your device settings and manually give your app the permissions it needs to run. 如果您需要快速尝试的方法,则可以进入设备设置并手动为您的应用授予运行所需的权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM