2011-11-26 50 views
3

之前,我有设置类型“消息/ RFC822”的意图问题上安卓发送电子邮件与文件附件仿真器。我必须使用setType(“message/rfc822”),因为文件没有标准的MIME类型(sqlite数据库),我试图避免选择列表中的很多应用程序供用户选择。 对于所有的API之前的水平2.3.3我有一个错误:意图用的setType(“信息/ RFC822”)为Android API级别2.3.3

java.lang.RuntimeException: 
Unable to start activity ComponentInfo{my.cashwatcher/my.cashwatcher.SendEmailActivity}: 
android.content.ActivityNotFoundException: 
No Activity found to handle Intent { act=android.intent.action.SEND typ=message/rfc822 
(has extras) } 

在API级别的情况下2.3.3代码工作正常和错误不会出现。这是一个Android模拟器或旧API的问题!?

代码:

Intent sendIntent = new Intent(Intent.ACTION_SEND);       
sendIntent.setType("message/rfc822");    
sendIntent.putExtra(Intent.EXTRA_EMAIL , new String[]{appPrefs.getEmail("email")});     
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(Environment.getExternalStorageDirectory(), DATABASE_PATH))); 
sendIntent.putExtra(Intent.EXTRA_TEXT, "body_of_email"); 
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "APPLICATION_NAME"); 
startActivityForResult(sendIntent, EMAIL_SEND_RESULT); 

回答

8

首先,“以避免对用户的选择有很多的选择列表中的应用”,使用ACTION_SENDTOmailto:Uri

其次,您遇到的不是“Android模拟器问题”,也不是“旧API”。您需要1+个能够处理ACTION_SENDIntent和MIME类型message/rfc822的应用程序。不能保证任何给定的设备将支持该组合,更不用说任何给定的模拟器。您的代码需要处理该问题,就像使用ACTION_GOBBLEDYGOOK或MIME类型thisis/sonotreal或其他什么一样。

+5

对于“ACTION_SENDTO和mailto:Uri”提供一些示例,您是否如此善良: – isabsent

+8

@isabsent:您是否善于使用位于此页面右上角的搜索框? – CommonsWare

+0

在发布这个问题之前,我已经从SO和谷歌中读了很多。所有这些都不包含解决问题的办法。我意识到我可以将所有我想要的东西写入到我自己的Android设备操作系统中,但问这个问题的目的是要知道**是否已经存在适当的方式?** – isabsent

2

我已它使用如u desried URI例如一个应用程序: 我的功能上点击监听激活 :

if(v.getId()==R.id.button3) 
{ 
    intent=new Intent(Intent.ACTION_SEND); 
    intent.setData(Uri.parse("mailto")); 
    String[]to={"[email protected]","[email protected]"}; 
    intent.putExtra(Intent.EXTRA_EMAIL, to); 
    intent.putExtra(Intent.EXTRA_SUBJECT, "hello"); 
    intent.putExtra(Intent.EXTRA_TEXT, "hi"); 
    intent.setType("message/rfc822"); 
    chooser=intent.createChooser(intent, "send mail"); 
    startActivity(chooser); 

}

0

This is the solution. Use the below code, works perfect...Got the solution after a research.... :)

Intent testIntent = new Intent(Intent.ACTION_VIEW); 

乌里数据= URI。解析(“mailto:?subject =”+“blah blah subject”+“& body =”+“blah blah body”+“& to =”+“sendme @ m e.com“);
testIntent.setData(data);
startActivity(testIntent);

相关问题