Get real path from an audio Uri
<p>In my app the user can choose a notification using RingtonePreference. From the latter I'm able to retrieve the Uri of the selected notification, and using the following code to extract the real file name:</p>

<pre><code>private String getUriRealPath(Uri contentUri) {
    if (BuildConfig.DEBUG) {
        Log.d(TAG, "Getting real path of uri: " + contentUri.toString());
    }

    String path = null;
    final String[] projection = new String [] { MediaStore.Audio.Media.DATA };
    final Cursor cursor;

    try {
        cursor = mContext.getContentResolver().query(contentUri, projection, null, null, null);
        if (cursor != null &amp;&amp; cursor.moveToFirst()) {
            int idx = cursor.getColumnIndex(projection[0]);
             if (idx != -1) {
                 path = cursor.getString(idx);

                 if (BuildConfig.DEBUG) {
                     Log.d(TAG, "Real path is: " + path);
                 }
             }
             else {
                 if (BuildConfig.DEBUG) {
                     Log.d(TAG, "Path can't be resolved.");
                 }
             }
        }
    } catch (Exception e) {
        Log.e(TAG, "getUriRealPath - " + e);
    }

    return path;
}
</code></pre>

<p>However, once the user chooses a notification that was downloaded via a 3-rd party, the above code can't find the real path. 
The reason for the extraction is I need the path for playing the notification in a SoundPool object.</p>

<p>I may be over seeing this, but getContentResolver() returns a ContentResolver instance for my application. Should I be using a "global" ContentResolver ?</p>

<p>Thanks in advanced.</p>
