Android examples for Network:Uri
Obtain the real path (System path) of a content uri.
//package com.java2s; import android.content.Context; import android.database.Cursor; import android.net.Uri; import android.provider.MediaStore; public class Main { /**//from ww w .j a v a 2s .c o m * Obtain the real path (System path) of a content uri. * * @param ctx The context. * @param contentUri The URI and content. * @return The absolute path of the content's file pointer. */ public static String getRealPathFromUri(Context ctx, Uri contentUri) {// can post image String proj[] = new String[] { MediaStore.Images.Media.DATA }; Cursor cursor = ctx.getContentResolver().query(contentUri, proj, // Which columns to return null, // WHERE clause; which rows to return (all rows) null, // WHERE clause selection arguments (none) null); // Order-by clause (ascending by name) int column_index = cursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); String path = cursor.getString(column_index); return path; } }