2014-02-07 40 views
1

我嘗試這樣(我在計算器一個公認的答案看到的)附加在電子郵件意圖多個文件:Android的 - 在電子郵件意圖附加多個文件崩潰的Gmail

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

而不是Intent.ACTION_SEND,嘗試在創建intMail時使用Intent.ACTION_SEND_MULTIPLE。 請參閱this answer

+0

只適用於較新的API版本。我的應用程序適用於8以上的所有版本 – Anonymous

+0

'emailIntent.setType(「image/jpeg」);'在我的情況下也是需要的,當我連接多個圖像 – tomash

相關問題