-1

I am trying to read data from Google Play Music Database using ContentProvider. I have included the READ_EXTERNAL_STORAGE permission within my Manifest file but, at crash, the logcat shows that the permission is not provided. Do I need to use the "Requesting Permission at runtime". If yes, how?

Error message:

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()

Manifest:

<?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>

Ryan
  • 1
  • 4
  • Are you targeting API level 23 or higher? Because, if you are, you'll need to ask for the permission at runtime, yeah. – Tharkius Jun 30 '17 at 21:16
  • Possible duplicate of [READ\_EXTERNAL\_STORAGE permission for Android](https://stackoverflow.com/questions/32431723/read-external-storage-permission-for-android) – Bertrand Martel Jun 30 '17 at 21:18

2 Answers2

1

I would comment, but not enough reputation yet, but here is the documentation on runtime permissions for api 23 plus. Supplementary reponse building on @Tharkius comment:

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

Lew Perren
  • 1,209
  • 1
  • 10
  • 14
0

There's a very cool easy-to-use library for managing runtime permissions. Follow the documentation in that link, all you need to know is there, and you'll see how super easy it is to set up and use :D

Tharkius
  • 2,744
  • 2
  • 20
  • 31