我有针对ACTION_SEND意图过滤特定应用的代码。 但我无法设置gmail和邮件EXTRA_EMAIL。
我试着这样做:
String packageName = ri.activityInfo.packageName;
if(packageName.contains("email"))
{
emailIntent.setPackage(packageName);
}
else if( packageName.contains("android.gm") || packageName.contains("mail"))
{
Intent intent = new Intent();
intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
if(packageName.contains("android.gm")) {
intent.putExtra(Intent.EXTRA_SUBJECT, resources.getString(R.string.share_email_subject));
intent.putExtra(Intent.EXTRA_EMAIL,"boghche.app@gmail.com");
答案 0 :(得分:1)
EXTRA_EMAIL额外需要一个String数组。使用String Array构造函数
Intent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { "boghche.app@gmail.com" });
答案 1 :(得分:0)
你需要这样检查。
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "urSubject");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "ExtraText");
PackageManager pm = v.getContext().getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
for (final ResolveInfo app : activityList)
{
if ((app.activityInfo.name).contains("gmail"))
{
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
shareIntent.setComponent(name);
v.getContext().startActivity(shareIntent);
break;
}
}
答案 2 :(得分:0)
final Intent intent = new Intent(
android.content.Intent.ACTION_SEND);
intent.setType("*/*");
intent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"subject name");
intent.putExtra(android.content.Intent.EXTRA_STREAM,
Uri.fromFile(new File(file.toString())));
final PackageManager pm = getPackageManager();
final List<ResolveInfo> matches = pm.queryIntentActivities(
intent, 0);
ResolveInfo best = null;
for (final ResolveInfo info : matches)
if (info.activityInfo.packageName.endsWith(".gm")
|| info.activityInfo.name.toLowerCase()
.contains("gmail"))
best = info;
if (best != null)
intent.setClassName(best.activityInfo.packageName,
best.activityInfo.name);
startActivity(intent);