Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.database.Cursor; import android.net.Uri; import android.provider.OpenableColumns; public class Main { public static String getFileName(Uri uri, Context context) { String result = null; if (uri.getScheme().equals("content")) { Cursor cursor = context.getContentResolver().query(uri, null, null, null, null); try { if (cursor != null && cursor.moveToFirst()) { result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); } } finally { if (cursor != null) { cursor.close(); } } } if (result == null) { result = uri.getPath(); int cut = result.lastIndexOf('/'); if (cut != -1) { result = result.substring(cut + 1); } } return result; } }