title: Permission Denial: android.permission.READ_EXTERNAL_STORAGE
body: <p>I am using a MediaStore class in my application and facing the below error(logcat),</p>
  
  <pre><code>E/DatabaseUtils: Writing exception to parcel
  java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/audio/media from pid=5769, uid=10059 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
  at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:539)
  at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:452)
  at android.content.ContentProvider$Transport.query(ContentProvider.java:205)
  at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:112)
  at android.os.Binder.execTransact(Binder.java:446)
  05-11 17:27:35.982 5769-5769/com.media.wanware.fragmentdemo D/AndroidRuntime: Shutting down VM
  05-11 17:27:35.984 5769-5769/com.media.wanware.fragmentdemo E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.media.wanware.fragmentdemo, PID: 5769
  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.media.wanware.fragmentdemo/com.media.wanware.fragmentdemo.MainActivity}: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/audio/media from pid=5769, uid=10059 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
     at android.app.ActivityThread.access$800(ActivityThread.java:151)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
     at android.os.Handler.dispatchMessage(Handler.java:102)
     at android.os.Looper.loop(Looper.java:135)
     at android.app.ActivityThread.main(ActivityThread.java:5254)
     at java.lang.reflect.Method.invoke(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:372)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
  Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/audio/media from pid=5769, uid=10059 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
     at android.os.Parcel.readException(Parcel.java:1546)
     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
     at android.content.ContentProviderProxy.query(ContentProviderNative.java:421)
     at android.content.ContentResolver.query(ContentResolver.java:478)
     at android.content.ContentResolver.query(ContentResolver.java:422)
     at com.media.wanware.fragmentdemo.MainActivity.getAllSongsFromDevice(MainActivity.java:45)
     at com.media.wanware.fragmentdemo.MainActivity.onCreate(MainActivity.java:29)
     at android.app.Activity.performCreate(Activity.java:5990)
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
     at android.app.ActivityThread.access$800(ActivityThread.java:151) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:135) 
     at android.app.ActivityThread.main(ActivityThread.java:5254) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:372) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
  </code></pre>
  
  <p>I read this question,</p>
  
  <p><a href="https://stackoverflow.com/questions/28518297/android-reading-external-storage-gives-securityexception">Android reading external storage gives securityException</a></p>
  
  <p>But I have placed the permissions correctly in my manifest below,</p>
  
  <p><strong>Manifest.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.media.wanware.fragmentdemo"&gt;
  
      &lt;uses-sdk
          android:minSdkVersion="15"
          android:targetSdkVersion="19" /&gt;
  
      &lt;uses-permission
          android:name="android.permission.READ_EXTERNAL_STORAGE"
          android:maxSdkVersion="19" /&gt;
  
      &lt;uses-permission
          android:name="android.permission.WRITE_EXTERNAL_STORAGE"
          android:maxSdkVersion="19" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"&gt;
  
  
  
  
          &lt;activity android:name=".MainActivity"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>Also upon reading further I also went through this below question,</p>
  
  <p><a href="https://stackoverflow.com/questions/32635704/android-permission-doesnt-work-even-if-i-have-declared-it">Android permission doesn&#39;t work even if I have declared it</a></p>
  
  <blockquote>
    <p>The big reason for not getting your permission nowadays is because
    your project has a targetSdkVersion of 23 or higher</p>
    
    <p>For these permissions, not only does your targetSdkVersion 23+ app
    need to have the  element(s), but you also have to
    ask for those permissions at runtime from the user on Android 6.0+
    devices, using methods like checkSelfPermission() and
    requestPermissions().</p>
    
    <p>As a temporary workaround, drop your targetSdkVersion below 23.</p>
  </blockquote>
  
  <p>But my target SDK is below 23 only. <strong>Why I am getting the same error ?</strong></p>