title: Trouble with permission to access external storage android
body: <p>I'm trying to find all mp3 files in storage but my app is crashing and I used the logcat to see why and comes with problem with permission to access external storage but I already put the permission on manifest and I dont no why keep crashing. 
  First error: </p>
  
  <blockquote>
    <p>03-06 14:55:24.553: E/dex2oat(2796): Failed to create oat file:
    /data/dalvik-cache/x86/data@app@felipe.cursoandroid.com.musicbox-2@split_lib_dependencies_apk.apk@classes.dex:
    Permission denied</p>
  </blockquote>
  
  <p>and more errors:</p>
  
  <blockquote>
    <p>03-06 14:55:25.274: E/DatabaseUtils(1873): Writing exception to parcel
    03-06 14:55:25.274: E/DatabaseUtils(1873):
    java.lang.SecurityException: Permission Denial: reading
    com.android.providers.media.MediaProvider uri
    content://media/external/audio/media from pid=2783, uid=10057 requires
    android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
    03-06 14:55:25.274: E/DatabaseUtils(1873):    at
    android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:605)
    03-06 14:55:25.274: E/DatabaseUtils(1873):    at
    android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:480)
    03-06 14:55:25.274: E/DatabaseUtils(1873):    at
    android.content.ContentProvider$Transport.query(ContentProvider.java:211)
    03-06 14:55:25.274: E/DatabaseUtils(1873):    at
    android.content.ContentProviderNative.onTransact(ContentProviderNative.java:112)
    03-06 14:55:25.274: E/DatabaseUtils(1873):    at
    android.os.Binder.execTransact(Binder.java:453)</p>
  </blockquote>
  
  <p>My <code>MainActivity.java</code>:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      SongsManager songsManager = new SongsManager();
      songsManager.getSongs(this);
      ArrayList&lt;Song&gt; songList = songsManager.getSongsList();
      ArrayAdapter&lt;Song&gt; adapterSongList = new ArrayAdapter&lt;Song&gt;(this, android.R.layout.simple_list_item_1, songList);
      ListView listView = (ListView) findViewById(R.id.musicList);
      listView.setAdapter(adapterSongList);
  }
  }
  </code></pre>
  
  <p>My <code>SongsManager.java</code>:</p>
  
  <pre><code>public class SongsManager {
  
  private ArrayList&lt;Song&gt; songsList;
  public ArrayList&lt;Song&gt; getSongsList(){
      return songsList;
  }
  public void getSongs(Context ctx){
      ContentResolver musicResolver = ctx.getContentResolver();
      Uri musicUri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
      Cursor musicCursor = musicResolver.query(musicUri, null, null, null, null);
      if(musicCursor!=null &amp;&amp; musicCursor.moveToFirst()){
          //get columns
          int titleColumn = musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media.TITLE);
          int idColumn = musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media._ID);
          int artistColumn = musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media.ARTIST);
          int pathConlumn = musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media.DATA);
          do {
              long thisId = musicCursor.getLong(idColumn);
              String thisTitle = musicCursor.getString(titleColumn);
              String thisArtist = musicCursor.getString(artistColumn);
              String thisPath = musicCursor.getString(pathConlumn);
              songsList.add(new Song(thisId, thisTitle, thisArtist, thisPath));
          }
          while (musicCursor.moveToNext());
      }
  }
  }
  </code></pre>
  
  <p>my <code>manifest.xml</code></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="felipe.cursoandroid.com.musicbox"&gt;
      &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:roundIcon="@mipmap/ic_launcher_round"
          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>