Android - 在电子邮件意图中附加多个文件会导致Gmail崩溃

时间:2014-02-07 20:38:50

标签: android crash gmail email-attachments

我尝试以这种方式在电子邮件意图中附加多个文件(我在stackoverflow中接受的答案中看到):

String[] attachments;<--contains all the filenames i want to attach;
ArrayList<Uri> uris = new ArrayList<Uri>();

for (String file : attachments){
    if(!file.equals("")){
        Log.w("-"+file +"-","attached");
        File fileIn = new File(file);
        Uri u = Uri.fromFile(fileIn);
        uris.add(u);
    }
}
//check that uri list is correct
for(Uri uri1:uris){
    Log.w(uri1.toString(),"uri list");
}

intMail.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);

此代码导致G​​mail客户端崩溃,logcat显示为警告:

Key android.intent.extra.STREAM expected Parcelable but value was a java.util.ArrayList.The default value <null> was returned.

之后,Gmal崩溃,logcat说

E/AndroidRuntime(10355): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.android.gm/com.google.android.gm.ComposeActivity}: java.lang.NullPointerException

我不知道我做错了什么......任何有用的建议/意见?

1 个答案:

答案 0 :(得分:1)

在创建intMail时,尝试使用Intent.ACTION_SEND_MULTIPLE而不是Intent.ACTION_SEND。 见this answer