gpt4 book ai didi

Android Intent 选择器不能有空的 Intent 目标

转载 作者:行者123 更新时间:2023-11-30 00:07:23 26 4
gpt4 key购买 nike

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_SUBJECT, "subject to be shared");
if (TextUtils.equals(packageName, "com.facebook.katana")) {
targetedShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "http://link-to-be-shared.com");
} else {
targetedShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "text message to shared");
}
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);
}

为了可视化共享中所需的应用程序,我需要传递:

 Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Select app to share");

为什么我需要:targetedShareIntents.remove(0) 这是否意味着从 targetedShareIntents 中删除了一个 Intent ?

我已经看到这段代码被大量使用。我不明白为什么我们需要使用删除。谢谢

最佳答案

targetedShareIntents.remove(0) 表示删除第一个元素后抛出列表...因为第一个 targetedShareIntent 包名称是 com.google.android.apps.docs 所以 documentation app 是不必要的 ..所以删除不必要的应用程序更好..因为用户不想发送数据到它...这就是从列表中删除 targetedShareIntent 的原因...您可以记录并检查包名称...

    Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(shareIntent, 0);

Log.e("package",resInfo.get(0).activityInfo.packageName);

关于Android Intent 选择器不能有空的 Intent 目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48747223/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com