Get Path from Uri and ContentResolver : ContentResolver « Core Class « Android






Get Path from Uri and ContentResolver

   

import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;

 class PathFromUri
{
    public static String retrieve(ContentResolver resolver, Uri uri)
    {
        if (uri.getScheme().equals("file"))
        {
            return uri.getPath();
        }
        final Cursor cursor = resolver.query(uri, new String[]{"_data"}, null, null, null);
        if (cursor.moveToFirst())
        {
            return cursor.getString(0);
        }
        throw new RuntimeException("Can't retrieve path from uri: " + uri.toString());
    }
}

   
    
    
  








Related examples in the same category

1.Using ContentResolver
2.get Content Name