Я попробовал свои вещи, чтобы отображать приложение sms только в диалоговом окне общего доступа, но не удалось для решения этой проблемы, если кто-нибудь знает об этой проблеме, пожалуйста, помогите я. Вот мой код, в основном у меня есть три типа в категории электронной почты я хотите отобразить приложение электронной почты в диалоговом окне общего доступа, а в случае смс я хочу показывать только приложение sms, и в случае, если я хочу отображать приложение sms и электронная почта в диалоговом окне share.only sms case failed
if (checkEmailSMS.equals("sms")) {
Resources resources = mContext.getResources();
Intent emailIntent = new Intent();
emailIntent.setAction(Intent.ACTION_SEND);
// Native email client doesn't currently support HTML, but it doesn't hurt to try in case they fix it
emailIntent.putExtra(Intent.EXTRA_TEXT, "email");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "text");
emailIntent.setType("message/rfc822");
PackageManager pm = mContext.getPackageManager();
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
Intent openInChooser = Intent.createChooser(emailIntent, "Share Via");
List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0);
List<LabeledIntent> intentList = new ArrayList<>();
for (int i = 0; i < resInfo.size(); i++) {
// Extract the label, append it, and repackage it in a LabeledIntent
ResolveInfo ri = resInfo.get(i);
String packageName = ri.activityInfo.packageName;
if (packageName.contains("android.email")) {
// emailIntent.setPackage(packageName);
} else if (packageName.contains("mms")) {
Intent intent = new Intent();
intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
intent.setAction(Intent.ACTION_SEND);
String smsBody="Sms Body";
intent.putExtra("sms_body", smsBody);
intent.setType("vnd.android-dir/mms-sms");
if (packageName.contains("mms")) {
intent.putExtra(Intent.EXTRA_TEXT, "Join me on Favorite Run! You can track your runs, create and paticipate in campaigns. Check it out here :");
}
intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon));
}
}
// convert intentList to array
LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]);
openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
mContext.startActivity(openInChooser);
} else if (checkEmailSMS.equals("email")){
Resources resources = mContext.getResources();
Intent emailIntent = new Intent();
emailIntent.setAction(Intent.ACTION_SEND);
// Native email client doesn't currently support HTML, but it doesn't hurt to try in case they fix it
emailIntent.putExtra(Intent.EXTRA_TEXT, "email");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "text");
emailIntent.setType("message/rfc822");
PackageManager pm = mContext.getPackageManager();
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
Intent openInChooser = Intent.createChooser(emailIntent, "Share Via");
List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0);
List<LabeledIntent> intentList = new ArrayList<>();
for (int i = 0; i < resInfo.size(); i++) {
// Extract the label, append it, and repackage it in a LabeledIntent
ResolveInfo ri = resInfo.get(i);
String packageName = ri.activityInfo.packageName;
if (packageName.contains("android.email")) {
emailIntent.setPackage(packageName);
} else if (packageName.contains("android.gm")) {
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")) { // If Gmail shows up twice, try removing this else-if clause and the reference to "android.gm" above
intent.putExtra(Intent.EXTRA_TEXT, "gmail");
intent.putExtra(Intent.EXTRA_SUBJECT, "subject gmail");
intent.setType("message/rfc822");
}
intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon));
}
}
// convert intentList to array
LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]);
openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
mContext.startActivity(openInChooser);
} else if (checkEmailSMS.equals("both")) {
Resources resources = mContext.getResources();
Intent emailIntent = new Intent();
emailIntent.setAction(Intent.ACTION_SEND);
// Native email client doesn't currently support HTML, but it doesn't hurt to try in case they fix it
emailIntent.putExtra(Intent.EXTRA_TEXT, "email");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "text");
emailIntent.setType("message/rfc822");
PackageManager pm = mContext.getPackageManager();
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
Intent openInChooser = Intent.createChooser(emailIntent, "Share Via");
List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0);
List<LabeledIntent> intentList = new ArrayList<>();
for (int i = 0; i < resInfo.size(); i++) {
// Extract the label, append it, and repackage it in a LabeledIntent
ResolveInfo ri = resInfo.get(i);
String packageName = ri.activityInfo.packageName;
if (packageName.contains("android.email")) {
emailIntent.setPackage(packageName);
} else if (packageName.contains("mms") || packageName.contains("android.gm")) {
Intent intent = new Intent();
intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
if (packageName.contains("mms")) {
intent.putExtra(Intent.EXTRA_TEXT, "Join me on Favorite Run! You can track your runs, create and paticipate in campaigns. Check it out here :");
} else if (packageName.contains("android.gm")) { // If Gmail shows up twice, try removing this else-if clause and the reference to "android.gm" above
intent.putExtra(Intent.EXTRA_TEXT, "gmail");
intent.putExtra(Intent.EXTRA_SUBJECT, "subject gmail");
intent.setType("message/rfc822");
}
intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon));
}
}
// convert intentList to array
LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]);
openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
mContext.startActivity(openInChooser);
}