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:
Thank you everyone, i solved the problem. But i want to point out an error above. I guess the mobile phone you test is HTC. I use the code above run correctly on my HTC mobile phone, but when i run it on Lenovo mobile phone or M9(A mobile phone from China) i can not get the name of the email file. When id debug the code the variable "nameIndex" return "-1" not the correct number "0", so i can not get the name of the email file. Looking for an afternoon, and finally solve the problem.
public static String getEmailFileName(ContentResolver resolver, Uri uri){
Cursor cursor = resolver.query(uri, new String[]{"_display_name"}, null, null, null);
cursor.moveToFirst();
int nameIndex = cursor.getColumnIndex("_display_name");
if (nameIndex >= 0) {
return cursor.getString(nameIndex);
} else {
return null;
}
}