我正在尝试使用 ContentProvider 从 Google Play音乐数据库中读取数据。我在我的Manifest文件中包含了 READ_EXTERNAL_STORAGE 权限,但是在崩溃时,logcat显示未提供权限。我是否需要使用“运行时请求权限”。如果是,怎么样?
错误讯息:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.ryanbansal.mymusic/com.app.ryanbansal.mymusic.Requested}: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/audio/albums from pid=11192, uid=10240 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.app.ryanbansal.mymusic">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:hardwareAccelerated="true"
android:allowBackup="true"
android:icon="@drawable/headphonesicon"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Home">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Requested"
android:label="Requested Results" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".Home"/>
</activity>
<activity
android:name=".Webpage"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="More info"
android:theme="@style/FullscreenTheme" >
</activity>
<service
android:name=".MyIntentService"
android:enabled="true"
android:exported="false" />
</application>
答案 0 :(得分:1)
我会评论,但还没有足够的声誉,但这里有关于api 23 plus的运行时权限的文档。关于@Tharkius的补充回应评论:
https://developer.android.com/training/permissions/requesting.html
答案 1 :(得分:0)
有一个very cool easy-to-use library用于管理运行时权限。按照该链接中的文档,您需要知道的就是那里,您将看到设置和使用它是多么容易:D