title: Android - open audio content uri with an Intent
body: <p>I have an app that lets users make a list of songs that they choose from their device.  They can then choose a song to play and the app will open the song's uri with an Intent so that the default music player is used to actually play the song.</p>
  
  <p>This is working fine if I choose the song with Astro file manager but if I choose a file through google Drive, the Audio section or the Downloads section then the song will not play.</p>
  
  <p>I'm choosing the files with an Intent like so:</p>
  
  <pre><code>Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
  intent.setType("audio/*");
  intent = Intent.createChooser(intent, "Select audio or music");
  </code></pre>
  
  <p>And then retrieving the Uri with <code>data.getData()</code>.</p>
  
  <p>To later open the Uri Im using an intent like:</p>
  
  <pre><code>Intent intent = new Intent(Intent.ACTION_VIEW, uri);
  context.startActivity(intent);
  </code></pre>
  
  <p>Astro file manager is returning Uris in the form <code>file:///storage/sdcard0/Download/My%20Song.mp3</code> and these ones open and play fine with the default media app.</p>
  
  <p>Google drive is returning Uris in the form <code>content://com.google.android.apps.docs.storage/document/acc%3D1%3Bdoc%3D421</code>.
  When I try to open Uris like that with an Intent using the default media app it shows a popup "Couldn't play the track that you requested".</p>
  
  <p>How do I open a content Uri that Google Drive is returning with the default app for that media type?</p>
  
  <p><strong>Edit</strong>: I have also tried explicitly setting the mime type when opening the uri with the Intent:</p>
  
  <pre><code>Intent intent = new Intent(Intent.ACTION_VIEW, audio.getAudioUri());
  intent.setType("audio/*");
  contentController.startActivity(intent);
  </code></pre>
  
  <p>When I do this it opens with VLC media player and VLC reports the error "VLC encountered an error with this media.  Please try refreshing the media library."</p>
  
  <p><strong>EDIT 2</strong>: It's always opening with VLC even though I'm forcing a chooser:</p>
  
  <pre><code>Intent intent = new Intent(Intent.ACTION_VIEW, uri);
  intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
  intent.setType("audio/*");
  Intent chooser = Intent.createChooser(intent, "Play the song with");
  //contentController.startActivity(intent);
  contentController.startActivity(chooser);
  </code></pre>
  
  <p>I've even tried Settings->Apps->Reset app preferences and it's still always defaulting to VLC.  This is on a Nexus 5 running Android 5.1.</p>
  
  <p><strong>Edit 3</strong>: Logcat errors
  I'm seeing these errors in the logcat window:</p>
  
  <pre><code>04-14 09:26:27.869  29143-29143/com.my.app E/Audio﹕ Permission Denial: opening provider com.google.android.apps.docs.storagebackend.StorageBackendContentProvider from ProcessRecord{2f0a6a28 29143:com.my.app/u0a80} (pid=29143, uid=10080) requires android.permission.MANAGE_DOCUMENTS or android.permission.MANAGE_DOCUMENTS
  04-14 09:26:27.871  29143-29143/com.my.app E/Audio﹕ Permission Denial: opening provider com.google.android.apps.docs.storagebackend.StorageBackendContentProvider from ProcessRecord{2f0a6a28 29143:com.my.app/u0a80} (pid=29143, uid=10080) requires android.permission.MANAGE_DOCUMENTS or android.permission.MANAGE_DOCUMENTS
  </code></pre>
  
  <p>In the AndroidManifest.xml of the app I do have that specified:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.MANAGE_DOCUMENTS" /&gt;
  </code></pre>
  
  <p><strong>Edit 4</strong>:
  Well this appears to be device specific.  All of the testing above was done on the Nexus 5.  I've just tested on my Nexus 7 (Android 5.0.2) and opening the content uri with the direct Intent rather than the chooser works with no errors.</p>