很抱歉,如果问题已经提出,我进行了很多搜索,但找不到。
我的疑问是,当我在做共享图像/测试的隐式意图时,它会向我显示各种选项,例如WhatsApp,Facebook,Message等。但是,我只想显示两个选项,例如Whatsapp和消息。
对于WhatsApp,我知道该程序包,但对于移动应用程序中的Message应用程序却不知道。
所以
预先感谢
答案 0 :(得分:1)
第一季度的答案
使用此方法查找默认软件包。
public static String getDefaultSmsAppPackageName(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
return Telephony.Sms.getDefaultSmsPackage(context);
else {
Intent intent = new Intent(Intent.ACTION_VIEW)
.addCategory(Intent.CATEGORY_DEFAULT).setType("vnd.android-dir/mms-sms");
final List<ResolveInfo> resolveInfos = context.getPackageManager().queryIntentActivities(intent, 0);
if (resolveInfos != null && !resolveInfos.isEmpty())
return resolveInfos.get(0).activityInfo.packageName;
return null;
}
}
第二季度的答案
List<Intent> targetedShareIntents = new ArrayList<Intent>();
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(shareIntent, 0);
if (!resInfo.isEmpty()) {
for (ResolveInfo resolveInfo : resInfo) {
String packageName = resolveInfo.activityInfo.packageName;
Intent targetedShareIntent = new Intent(android.content.Intent.ACTION_SEND);
targetedShareIntent.setType("text/plain");
targetedShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "text message to shared");
targetedShareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "subject to be shared");
if (packageName.contains(getDefaultSmsAppPackageName(context))||packageName.contains("com.whatsapp")) {
targetedShareIntent.setPackage(packageName);
targetedShareIntents.add(targetedShareIntent);
}
}
Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Select app to share");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[targetedShareIntents.size()]));
startActivity(chooserIntent);
答案 1 :(得分:0)
您可以尝试
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_APP_MESSAGING);
intent.addCategory(Intent.CATEGORY_APP_BROWSER)
startActivity(intent);