我正嘗試從中讀取數據Google Play音樂數據庫使用ContentProvider。我在我的Manifest文件中包含了READ_EXTERNAL_STORAGE權限,但在崩潰時,logcat顯示未提供權限。我是否需要使用「在運行時請求權限」。如果是,如何?Android權限拒絕
錯誤消息:
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>
您是針對API等級23還是更高?因爲,如果你是,你需要在運行時詢問權限,是的。 – Tharkius
[READ \ _EXTERNAL \ _STORAGE權限爲Android]可能的重複(https://stackoverflow.com/questions/32431723/read-external-storage-permission-for-android) –