I\'m trying to load an email attachment in my application. I can get the content, but I cannot get the file name.
Here\'s how my intent filter looks like:
The constant MediaStore.MediaColumns.DISPLAY_NAME
resolves to the string "_display_name"
. The array you put in with this string is used to select the columns you want to get with the query. The behavior of null
for this parameter might be different for the various phones? Returning all columns (as it should according to the javadoc) by HTC phones and none for others?
The javadoc states you should retrieve specific columns for performance reasons. By returning nothing on the null
argument, the manufacturers might want to enforce this performance 'optimization'.
This should therefore work on all phones:
public static String getContentName (ContentResolver resolver, Uri uri) {
Cursor cursor = resolver.query(uri,
new String[]{MediaStore.MediaColumns.DISPLAY_NAME}, null, null, null);
cursor.moveToFirst();
int nameIndex = cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME);
if (nameIndex >= 0) {
return cursor.getString(nameIndex);
}
return null;
}
I cannot test this, because I only have a HTC phone :).