Need a path from your uri. there is a way to get the path from uri.
public String getPath(Context context, Uri uri) throws URISyntaxException { if ("content".equalsIgnoreCase(uri.getScheme())) { String[] projection = { "_data" }; Cursor cursor = null; try { cursor = context.getContentResolver().query(uri, projection, null, null, null); int column_index = cursor.getColumnIndexOrThrow("_data"); if (cursor.moveToFirst()) { return cursor.getString(column_index); } } catch (Exception e) { // Eat it } } else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; }
Get file name
try{ //call the getPath uri with context and uri //To get path from uri String path = getPath(this, uri); File file = new File(path); String filename = file.getName(); Log.e(TAG, "File Name: " + filename); }catch(Exception e){ e("Err", e.toString()+""); }
Output
uri: content://com.android.providers.media.documents/document/image%3A12876 FileName : profile.png
user4696837
source share