2017-06-30 225 views
-1

我正尝试从中读取数据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> 

+0

您是针对API等级23还是更高?因为,如果你是,你需要在运行时询问权限,是的。 – Tharkius

+0

[READ \ _EXTERNAL \ _STORAGE权限为Android]可能的重复(https://stackoverflow.com/questions/32431723/read-external-storage-permission-for-android) –

回答

0

有用于管理运行权限的very cool easy-to-use library。请按照该链接中的文档,您需要知道的内容就在那里,您会看到设置和使用的超级简单性:D