2012-09-13 141 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); 

上面的链接显示了如何删除这些文件,并说明如何将它们放在正确的文件夹中以避免覆盖其他文件。 希望这可以帮助任何其他人有相同的问题

相关问题