[英]Intent with setType("message/rfc822") for Android API Level before 2.3.3
I have a problem with setting type "message/rfc822" for intent to send e-mail with file attachment on Android emulator .我在设置类型“message/rfc822”时遇到问题,以便在Android 模拟器上发送带有文件附件的电子邮件。 I have to use setType("message/rfc822") because the file doesn't have standard MIME-type (SQLite database) and I am trying to avoid a lot of applications in the select list for user's choice.
我必须使用 setType("message/rfc822") 因为该文件没有标准的 MIME 类型(SQLite 数据库),我试图避免选择列表中的大量应用程序供用户选择。 For all API Levels before 2.3.3 I have an error:
对于 2.3.3 之前的所有 API 级别,我有一个错误:
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) }
In the case of API Level, 2.3.3 code works fine and error doesn't appear.在 API 级别的情况下,2.3.3 代码工作正常并且不会出现错误。 Is it a problem with the Android emulator or old APIs!?
是安卓模拟器还是旧API的问题!?
Code:代码:
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);
First, "to avoid a lot of applications in select list for user's choice", use ACTION_SENDTO
and a mailto:
Uri
.首先,“为了避免用户选择的选择列表中有很多应用程序”,使用
ACTION_SENDTO
和一个mailto:
Uri
。
Second, what you are experiencing is not "a problem of Android emulator" nor "old APIs".其次,您遇到的不是“Android 模拟器问题”或“旧 API”。 You need 1+ applications that are capable of handling the
ACTION_SEND
Intent
and a MIME type of message/rfc822
.您需要 1+ 个能够处理
ACTION_SEND
Intent
和 MIME 类型的message/rfc822
。 There is no guarantee that any given device will support that combination, let alone any given emulator.不能保证任何给定的设备都支持该组合,更不用说任何给定的模拟器了。 Your code needs to handle that, just as if you use
ACTION_GOBBLEDYGOOK
or a MIME type of thisis/sonotreal
or whatever.您的代码需要处理这个问题,就像您使用
ACTION_GOBBLEDYGOOK
或thisis/sonotreal
或其他类型的 MIME 类型thisis/sonotreal
。
I have made an application that uses URI example as you desired:我制作了一个应用程序,根据需要使用 URI 示例:
if(v.getId()==R.id.button3)
{
intent=new Intent(Intent.ACTION_SEND);
intent.setData(Uri.parse("mailto"));
String[]to={"akshkatheria@gmail.com","megakatheria@gmail.com"};
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);
}
This is the solution.
这就是解决方案。 Use the below code, works perfectly...Got the solution after research.... :)
使用下面的代码,完美运行......研究后得到了解决方案...... :)
Intent testIntent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("mailto:?subject=" + "blah blah subject" + "&body=" +
"blah blah body" + "&to=" + "sendme@me.com");
testIntent.setData(data);
startActivity(testIntent);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.