从Android的意图过滤器获取邮箱地址 [英] Get Email Address from Intent Filter in Android
本文介绍了从Android的意图过滤器获取邮箱地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎样才能在谈到Android的意图通过过滤电子邮件?
目前,我想这一点,我能得到并发送,但Extra_EMail为null。
意向意图= getIntent();
字符串行动= intent.getAction();
字符串类型= intent.getType();
字符串sharedText = intent.getStringExtra(Intent.EXTRA_EMAIL);
如果(sharedText!= NULL){
Toast.makeText(getApplicationContext(),sharedText,
Toast.LENGTH_LONG).show(); mEdit.setText(sharedText);
}
解决方案
下面是我的助手功能可以发送电子邮件:
公共静态意向的电子邮件(上下文的背景下,字符串[]地址,主题字符串,字符串的身体,乌里附件){
意向意图=新意图(Intent.ACTION_SEND);
intent.setType(信息/ RFC822);
如果(地址!= NULL)
intent.putExtra(Intent.EXTRA_EMAIL,地址);
如果(身体!= NULL)
intent.putExtra(Intent.EXTRA_TEXT,体);
如果(主题!= NULL)
intent.putExtra(Intent.EXTRA_SUBJECT,学科);
如果(附件!= NULL)
intent.putExtra(Intent.EXTRA_STREAM,附件);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
返回意图;
}
您可以使用它的一个活动里面是这样的:
startActivity(电子邮件(这一点,新的String [] {abc@def.com,内部电子邮件消息,空)的电子邮件主题);
How can I get email that comes through intent-filter in android ? Currently I tried this, I could get the Action SEND, but the Extra_EMail is null.
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
String sharedText = intent.getStringExtra(Intent.EXTRA_EMAIL);
if (sharedText != null) {
Toast.makeText(getApplicationContext(), sharedText,
Toast.LENGTH_LONG).show();
mEdit.setText(sharedText);
}
解决方案
Here is my helper function to send emails:
public static Intent email(Context context, String[] addresses, String subject, String body, Uri attachment) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
if (addresses != null)
intent.putExtra(Intent.EXTRA_EMAIL, addresses);
if (body != null)
intent.putExtra(Intent.EXTRA_TEXT, body);
if (subject != null)
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
if (attachment != null)
intent.putExtra(Intent.EXTRA_STREAM, attachment);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return intent;
}
You can use it this way inside an Activity:
startActivity(email(this, new String [] {"abc@def.com", "Subject of email", "Message inside email", null));
这篇关于从Android的意图过滤器获取邮箱地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文