title: Error requires 'android.permission.READ_EXTERNAL_STORAGE' or grantUriPermission()
body: <p><strong>I'm reading file from sd card but getting above error though i have mentioned all external storage permission in manifest but still getting above error.</strong></p>
  
  <p>This is my logcat:      </p>
  
  <blockquote>
    <p>java.lang.RuntimeException: Unable to start activity
    ComponentInfo{com.example.murarilal.listview/com.example.murarilal.listview.MainActivity}:
    java.lang.SecurityException: Permission Denial: reading
    com.android.providers.media.MediaProvider uri
    content://media/external/audio/media from pid=12518, uid=10087
    requires android.permission.READ_EXTERNAL_STORAGE, or
    grantUriPermission()
                                                                                                at
    android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
                                                                                                at
    android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
                                                                                                at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                                                at
    android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
                                                                                                at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                                at android.os.Looper.loop(Looper.java:154)
                                                                                                at android.app.ActivityThread.main(ActivityThread.java:6077)
                                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                                at
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
                                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
                                                                                             Caused by: java.lang.SecurityException: Permission Denial: reading
    com.android.providers.media.MediaProvider uri
    content://media/external/audio/media from pid=12518, uid=10087
    requires android.permission.READ_EXTERNAL_STORAGE, or
    grantUriPermission()
                                                                                                at android.os.Parcel.readException(Parcel.java:1683)
                                                                                                at
    android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
                                                                                                at
    android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
                                                                                                at
    android.content.ContentProviderProxy.query(ContentProviderNative.java:421)
                                                                                                at android.content.ContentResolver.query(ContentResolver.java:530)
                                                                                                at android.content.ContentResolver.query(ContentResolver.java:472)
                                                                                                at
    com.example.murarilal.listview.MainActivity.getMusic(MainActivity.java:57)
                                                                                                at
    com.example.murarilal.listview.MainActivity.doStuff(MainActivity.java:77)
                                                                                                at
    com.example.murarilal.listview.MainActivity.onCreate(MainActivity.java:48)
                                                                                                at android.app.Activity.performCreate(Activity.java:6662)
                                                                                                at
    android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
                                                                                                at
    android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
                                                                                                at
    android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
                                                                                                at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                                                                                                at
    android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
                                                                                                at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                                at android.os.Looper.loop(Looper.java:154) 
                                                                                                at android.app.ActivityThread.main(ActivityThread.java:6077) 
                                                                                                at java.lang.reflect.Method.invoke(Native Method) 
                                                                                                at
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 
                                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)</p>
  </blockquote>
  
  <p><strong>Note : I am reading files from sdcard. I think the error is in getMusic() function withe the cursor. Please help me with this.</strong></p>
  
  <p><strong>MainActivity Code</strong></p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      private static final int MY_PERMISSION_REQUEST = 1;
      ArrayList&lt;String&gt; arrayList;
      ListView listView;
      ArrayAdapter&lt;String&gt; adapter;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
  
          if (ContextCompat.checkSelfPermission(MainActivity.this,
                  Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_DENIED) {
              if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE)) {
                  ActivityCompat.requestPermissions(MainActivity.this,
                          new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, MY_PERMISSION_REQUEST);
  
              } else {
                  ActivityCompat.requestPermissions(MainActivity.this,
                          new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, MY_PERMISSION_REQUEST);
  
              }
          } else {
              doStuff();
          }
  
      }
  
      public void getMusic()
      {
          ContentResolver contentResolver=getContentResolver();
          Uri songUri =MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
          Cursor songCursor=contentResolver.query(songUri,null,null,null,null);
          {
              if(songCursor!=null &amp;&amp; songCursor.moveToFirst())
              {
                  int songTitle=songCursor.getColumnIndex(MediaStore.Audio.Media.TITLE);
                  int songArtist=songCursor.getColumnIndex(MediaStore.Audio.Media.ARTIST);
                  do{
                      String currentTitle=songCursor.getString(songTitle);
                      String currentArtist=songCursor.getString(songArtist);
                      arrayList.add(currentTitle +"\n"+currentArtist);
  
                  }while (songCursor.moveToFirst());
  
              }
          }
      }
  
      public void doStuff() {
          listView = (ListView) findViewById(R.id.listView);
          arrayList = new ArrayList&lt;&gt;();
          getMusic();
          adapter = new ArrayAdapter&lt;&gt;(this, android.R.layout.simple_list_item_1,arrayList);
          listView.setAdapter(adapter);
  
          listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int i, long l) {
  
              }
          });
  
  
      }
  
  
  
      @Override
      public void onRequestPermissionsResult ( int requestCode, String[] permissions,int[] grantResults){
          switch (requestCode) {
              case MY_PERMISSION_REQUEST:
                  if (grantResults.length &gt; 0 &amp;&amp; grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                      {
                          if (ContextCompat.checkSelfPermission(MainActivity.this,
                                  Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_DENIED) {
                              Toast.makeText(this, "permission granted", Toast.LENGTH_LONG).show();
                              doStuff();
                          } else {
                              Toast.makeText(this, "no permission granted", Toast.LENGTH_LONG).show();
                              finish();
                          }
  
                      }
                      return;
                  }
          }
      }
  
  
  
  }
  </code></pre>
  
  <p>Anyhelp would be appreciated thanks.</p>