Here you can find the source of getNameFromUri(Context context, Uri uri)
public static String getNameFromUri(Context context, Uri uri)
//package com.java2s; //License from project: Open Source License import android.content.Context; import android.database.Cursor; import android.net.Uri; import android.provider.OpenableColumns; import java.io.File; public class Main { public static String getNameFromUri(Context context, Uri uri) { if (uri.getScheme().equals("file")) { return new File(uri.getPath()).getName(); } else if (uri.getScheme().equals("content")) { Cursor cursor = context.getContentResolver().query(uri, null, null, null, null, null); try { if (cursor != null && cursor.moveToFirst()) { return cursor.getString(cursor .getColumnIndex(OpenableColumns.DISPLAY_NAME)); }//from w w w .j a v a 2 s .c om } finally { cursor.close(); } } return null; } }