2012-09-13 199 views
3

我在android上工作,試圖發送帶有附加文件的電子郵件,但出現以下錯誤。將PDF文件附加到應用程序的電子郵件

android.content.ActivityNotFoundException:無活動處理 意向{行動= android.intent.action.SENDTO DAT =文件://assets/Cards/myfile.pdf典型值=應用程序/ PDF FLG = 0x10000000的 (有演員)}

林Android開發人員因此Im有點兒丟失什麼,我需要做的非常新。以下是我目前正在嘗試的內容

Intent intent = new Intent(Intent.ACTION_SENDTO); // it's not ACTION_SEND 
intent.setType("text/plain"); 
intent.putExtra(Intent.EXTRA_SUBJECT, "Card Set ")); 
intent.putExtra(Intent.EXTRA_TEXT, ""); 
intent.setData(Uri.parse("mailto:")); 
intent.setDataAndType(Uri.parse("file://assets/Cards/" + "myfile.pdf"), 
                  "Applications/pdf"); 
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
activity.startActivity(intent); 

我可以在不附加文件的情​​況下正常創建和發送電子郵件。我如何應安裝文件中的任何幫助,正確地將是巨大的感謝

+0

在真正的設備NOT IN EMULATOR測試它。如果這沒有幫助,然後嘗試設置intent.setType(「application/pdf」);並看到結果。 –

+0

是啊我一直在設備上測試,並嘗試設置應用程序/ pdf,但它給了我相同的錯誤 – glogic

+0

嘗試設置您的意圖Intent.ACTION_SEND。正確的PDF文件的MIME類型是「application/pdf」而不是「Applications/pdf」 –

回答

1

好感謝卡爾蒂克的鏈接我設法追查正確的方式(以及工作方式)附加文件。 周圍搜索後,我發現這表明如何將文件存儲到外部存儲 http://developer.android.com/reference/android/os/Environment.html#getExternalStoragePublicDirectory%28java.lang.String%29

,所以我使用修改後的createExternalStoragePublicPicture(),它是此頁面上寫入內存,然後我做以下

createExternalStoragePublicPicture(); 
File path = Environment.getExternalStoragePublicDirectory(
               Environment.DIRECTORY_PICTURES); 
             File file = new File(path, "cards_01.pdf"); 
Intent intent = new Intent(Intent.ACTION_SEND ,Uri.parse("mailto:")); // it's not ACTION_SEND 
intent.setType("text/plain"); 
intent.putExtra(Intent.EXTRA_SUBJECT, "Card Set "); 
intent.putExtra(Intent.EXTRA_TEXT, ""); 
intent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(file)); 
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // this will make such that when user returns to your app, your app is displayed, instead of the email app. 
activity.startActivity(intent); 

上面的鏈接顯示瞭如何刪除這些文件,並說明如何將它們放在正確的文件夾中以避免覆蓋其他文件。 希望這可以幫助任何其他人有相同的問題

相關問題