Android - get email attachment name in my application

后端 未结 4 1732
独厮守ぢ
独厮守ぢ 2020-12-18 02:16

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:

         


        
4条回答
  •  失恋的感觉
    2020-12-18 02:25

    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;
    }
    

    }

提交回复
热议问题