空意图选择器(没有应用程序可以执行此操作)

2023-11-30

我的意图选择器基于白名单(只有部分应用程序会显示在意图选择器中)。该代码基于另一个相反的代码;将应用程序列入黑名单。我从那里得到了该代码here and this是与之相关的相关讨论。

如何创建选择器的上下文:

        String[] whitelist = new String[] { "org.schiphol", "nl.negentwee", "org.schipholsecurity", "org.chineseschiphol", "nl.ns", "com.tomtom" };

    Intent intent = new Intent(Intent.ACTION_MAIN);
    //intent.addCategory(Intent.CATEGORY_LAUNCHER);

    startActivity(generateCustomChooserIntent(intent, whitelist));

我用来创建白名单选择器的方法;

// Method:
private Intent generateCustomChooserIntent(Intent prototype, String[] whiteList) {
    List<Intent> targetedShareIntents = new ArrayList<Intent>();
    List<HashMap<String, String>> intentMetaInfo = new ArrayList<HashMap<String, String>>();
    Intent chooserIntent;

    Intent dummy = new Intent(prototype.getAction());
    dummy.setType(prototype.getType());
    List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(dummy, 0);
    MyLog.i(LOG_TAG, "Apps installed on device:" + resInfo.size());

    if (!resInfo.isEmpty()) {
        for (ResolveInfo resolveInfo : resInfo) {
            // MyLog.i(LOG_TAG, "Looking at:" + resolveInfo.activityInfo.packageName);

            if (resolveInfo.activityInfo == null) {
                MyLog.e(LOG_TAG, "resolved application has no activity info, so it is not usable.");
                continue;
            }

            if (Arrays.asList(whiteList).contains(resolveInfo.activityInfo.packageName)) {
                // MyLog.i(LOG_TAG, "=============================> accepted");

                HashMap<String, String> info = new HashMap<String, String>();
                info.put("packageName", resolveInfo.activityInfo.packageName);
                info.put("className", resolveInfo.activityInfo.name);
                info.put("simpleName", String.valueOf(resolveInfo.activityInfo.loadLabel(getPackageManager())));
                intentMetaInfo.add(info);
            } else {
                // MyLog.i(LOG_TAG, "rejected");
            }
        }

        if (!intentMetaInfo.isEmpty()) {
            MyLog.i(LOG_TAG, "--- done compiling list ---");

            // TODO enable sorting again
            // sorting for nice readability
            // Collections.sort(intentMetaInfo, new Comparator<HashMap<String, String>>() {
            // @Override
            // public int compare(HashMap<String, String> map, HashMap<String, String> map2) {
            // return map.get("simpleName").compareTo(map2.get("simpleName"));
            // }
            // });

            MyLog.i(LOG_TAG, "--- creating custom intent list ---");

            // create the custom intent list
            for (HashMap<String, String> metaInfo : intentMetaInfo) {
                MyLog.i(LOG_TAG, "adding " + metaInfo.get("packageName") + " to the intent list");

                Intent targetedShareIntent = (Intent) prototype.clone();
                targetedShareIntent.setPackage(metaInfo.get("packageName"));
                targetedShareIntent.setClassName(metaInfo.get("packageName"), metaInfo.get("className"));
                targetedShareIntents.add(targetedShareIntent);
            }

            MyLog.i(LOG_TAG, "--- done compiling intent list ---");
            MyLog.i(LOG_TAG, "total count targetedShareIntents: " + targetedShareIntents.size());

            chooserIntent = Intent.createChooser(targetedShareIntents.remove(targetedShareIntents.size() - 1), "Selecteer reis app (1)");
            MyLog.i(LOG_TAG, "--- chooser created ---");
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[] {}));

            MyLog.e(LOG_TAG, "returning filled (custom) chooser");
            return chooserIntent;
        }
    }

    MyLog.e(LOG_TAG, "returning default chooser (empty)");
    return Intent.createChooser(prototype, "Selecteer reis app");
}

现在发生的情况是,结果选择器显示“没有应用程序可以执行此操作”,而 logcat 显示选择了 5 个应用程序。

Logcat 记录结果:

06-28 13:04:48.679: I/NavigationTypeActivity(9400): Apps installed on device:356
06-28 13:04:48.687: I/NavigationTypeActivity(9400): --- done compiling list ---
06-28 13:04:48.687: I/NavigationTypeActivity(9400): --- creating custom intent list ---
06-28 13:04:48.687: I/NavigationTypeActivity(9400): adding org.chineseschiphol to the intent list
06-28 13:04:48.687: I/NavigationTypeActivity(9400): adding org.schiphol to the intent list
06-28 13:04:48.687: I/NavigationTypeActivity(9400): adding org.schipholsecurity to the intent list
06-28 13:04:48.687: I/NavigationTypeActivity(9400): adding nl.negentwee to the intent list
06-28 13:04:48.687: I/NavigationTypeActivity(9400): --- done compiling intent list ---
06-28 13:04:48.687: I/NavigationTypeActivity(9400): total count targetedShareIntents: 4
06-28 13:04:48.687: I/NavigationTypeActivity(9400): --- chooser created ---
06-28 13:04:48.687: E/NavigationTypeActivity(9400): returning filled (custom) chooser

我从一位 Android 专家那里得到了一些反馈,告诉我应该用工作意图来定义选择器,例如 Playstore 或 Gmail 之类的。理论上,您可以提供您自己的应用程序的启动意图(您确定您自己的应用程序已安装)。

Intent chooserIntent = Intent.createChooser(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=gmail")), "example");

后来,这就是列表从列表中删除单个项目的原因(您可能不希望在选择器中出现您自己的应用程序)。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

空意图选择器(没有应用程序可以执行此操作) 的相关文章

  • 将JSON数据解析到Android ListView中

    我已经潜伏这个网站很长一段时间了 幸运的是 到目前为止我所有的问题都得到了解答 我希望你们中的一些人能够阐明我的问题 我可以成功地让 ListView 来显示字符串数组 但是当我尝试将 JSON 数据解析为数组时 我的程序只是强制关闭 而
  • putExtra() 和 setData() 之间的区别

    putExtra 和 setData 有什么区别 我已经阅读了 android 文档 但没有太大帮助 还有之前的一个问题Intent setData 与 Intent putExtra https stackoverflow com que
  • 如何在android中批量插入sqlite

    我正在使用 SQLiteOpenHelper 进行数据插入 我需要插入2500个id和2500个名字 所以花费了太多时间 请任何人帮助我如何减少插入时间 我们可以一次插入多条记录吗 任何人都可以帮助我 先感谢您 代码 public clas
  • 如何将现有的 SQLite3 数据库导入 Room?

    好吧 我在桌面上使用 SQLite3 创建了一个只需要读取的某些信息的数据库 我正在制作的应用程序不需要在此表中插入或删除信息 我在 Room 数据库层上做了相当多的谷歌搜索 所有文档都需要在构建应用程序时在 Room 中创建一个新的数据库
  • 作为附件的 Android 设备

    我有 2 个 Android 设备 我想用 USB OTG 电缆连接它们 并在两个设备之间进行来回通信 据我了解 一台 Android 设备将充当 USB 主机 运行 4 4 的 Nexus 7 另一台 Android 设备将充当 USB
  • Android Studio 安装失败,APK 未签名

    最近从 Eclipse 更改为 Android Studio 我还更改了 JDKjava open jdk to jdk1 7 0 45 现在我尝试运行我的第一个应用程序 并收到以下消息 Installation failed since
  • org.apache.http.conn.HttpHostConnectException:在 android 中连接到 http://localhost 被拒绝

    我正在制作一个应用程序 在执行它时将图像上传到服务器并将其数据库更新到android中的服务器 它显示错误 Connection to http localhost refused 还有更多错误 我研究了这个问题 发现不是提供 URL 连接
  • 合并 dex 程序类型已存在时出错:android.support.v4.os.ResultReceiver$MyResultReceiver

    合并dex时出错 以下是依赖项 ext anko version 0 10 5 support lib 1 0 0 alpha1 room lib 1 1 0 dependencies implementation org jetbrain
  • 数据未刷新“DynamiteModule:未找到 com.google.firebase.auth 的本地模块描述符类”

    我已经使用 Firebase 很长时间了 到目前为止 除了以下场景之外 一切都很好 有时我注意到我的应用程序不再获取新数据 我正在用一个活跃的监听器监听变化 并且我确实有keepSynced set to true 发生这种情况时 我会在日
  • 垂直从上到下线手势检测器

    我用的是 手势工具 注意到对于垂直从上到下的线无法检测 因为我在代码中使用生成的手势文件 如下所示 但无法检测垂直从上到下的线手势检测 import java util ArrayList import android app Activi
  • 将触摸事件从 NestedScrollView 传递到父视图

    我在 NestedScrollView 下方有一个 ViewPager 宽度一些顶部填充 以及 ClipToPadding false 和透明背景 如图像 我的 ViewPager 无法获取触摸事件并且无法工作 我怎么解决这个问题 我无法更
  • 推特更新状态

    我正在通过 twitter4j 将 Twitter 集成到 Android 我可以成功阅读我发布的推文 现在我试图用它发布推文 但我不能 我收到如下奇怪的警告 02 01 16 28 43 298 WARN System err 729 4
  • 可用屏幕的尺寸

    我使用的是 Nexus 7 1280x800 android 4 2 2 API 17 我想获取屏幕的大小 将其划分为相同高度和宽度的正方形部分 我正在使用 FrameLayout 我的方块是 ImageView 的子类 我这样做 cont
  • 如何向开关对象添加/更改波纹效果

    下面是我自定义的开关 红圈是默认的波纹效果 我发现设置一个波纹可绘制作为开关的背景 控制波纹的颜色
  • 在循环中按名称访问变量

    我正在开发一个 Android 项目 并且有很多可绘制对象 这些绘图的名称都类似于icon 0 png icon 1 png icon 100 png 我想将这些可绘制对象的所有资源 ID 添加到整数 ArrayList 中 对于那些不了解
  • Android项目中使用java获取电脑的IP地址

    我在用ksoap2 android http code google com p ksoap2 android 我需要使用java获取IP地址 这样我就不必每次都手动输入它 我所说的 IP 地址是指 例如 如果我这样做ipconfig使用命
  • android 中的 java.net.URL ..新手问题

    我是java新手 正在尝试android开发 以下代码生成 malformedURLException 有人可以帮助我识别异常吗 任何提示都会非常有帮助 package com example helloandroid import and
  • 如何检测日期选择器对话框的取消单击?

    我正在使用以下 日期选择器的示例 http developer android com guide tutorials views hello datepicker html http developer android com guide
  • Android - 如何简单地拖放按钮?

    我在这里找到了一个适合初学者的教程 http androidrox wordpress com 2011 05 13 android sample app drag and drop image using touch http andro
  • 如何减少 Android 中浮动 editText 提示和 editText 框之间的空间?

    我有一个带有浮动提示的 EditText 但我想知道如何减少浮动提示和 EditText 框之间的空间 现在我的用户界面看起来像https i stack imgur com ltfra jpg https i stack imgur co

随机推荐

  • 子类中的狭义属性类型

    今天我遇到了一个奇怪的行为 我没想到 Objective C 编译器会允许 在 UITableViewCell 中 有一个名为 imageView 的 UIImageView 类型的属性 我对 UITableViewCell 进行了子类化
  • iDangero.us Swiper 多个实例

    我正在尝试添加多个刷卡器 http www idangero us swiper 在我的网站上 我想添加滑动器动态 因此我为每个滑动器使用相同的类 每个滑动器看起来像这样 div class swiper container div cla
  • JavaFX 任务一旦取消或完成一次就不会重新运行

    我正在做一个基本的 Java FX 任务练习 线程上的计数范围为 1 到 150 当前值显示在标签上并更新进度条 有一个按钮可以启动任务 取消任务以及查看任务的取消状态 让我困惑的是为什么我在取消线程一次后无法重新运行任务 如果我让任务完成
  • 对调用另一个方法的方法进行单元测试

    对调用多个方法的方法进行单元测试的最佳方法是什么 例如 modify string value if value Length gt 5 replaceit value else changeit value 该伪代码有一个修改方法 当前
  • Solr 4 中可以更新 uniqueKey 吗?

    我的 uniqueKey 定义为
  • 使用 Gradle - 在 META-INF/spring.factories 中找不到自动配置类

    尝试在 Spring Boot 上使用 IntelliJ 中的 gradle 中的 jar 函数部署我构建的 jar 它使用 bootrun 从我的 IDE 本地运行良好 但没有将 jar 放在 Linux 服务器上 服务器上的完整错误是
  • Sklearn Pipeline:自动错过一项功能

    我创建了一个自定义分类器 虚拟分类器 下面是定义 我还添加了一些打印语句和全局变量来捕获值 class FeaturePassThroughClassifier ClassifierMixin def init self pass def
  • 以编程方式触发来自 Google Play 的应用更新

    在 Google Play 开发者控制台中提交应用程序更新并且所有用户都可以看到该应用程序后 任何设备需要多长时间才能选择更新 假设全天都有有效的互联网 WiFi 连接 并且此应用程序已开启自动更新 我能否以编程方式向 Google Pla
  • React 正在将旧状态发送给其父级

    当我将子组件的状态发送到其父组件时 React 会将旧状态发送到父组件 我想在每次单击正常工作并调用函数handleClick 的列表项时发送更新的状态 但当我打电话时sendStateToParent 它正在过去旧的状态 假设我点击了IT
  • ASP.NET MVC 中的 AutoMapper 更新操作

    对于某些人来说 这可能非常简单 但是我有点困惑 找不到合适的例子 假设我正在使用视图模型 并且我的 POST 操作在该视图模型中进行 通常我会按照以下方式做一些事情 HttpPost public ActionResult Update U
  • 无法在 Spark SQL 中生成 UUID

    下面是代码块和收到的错误 gt creating a temporary views sqlcontext sql CREATE TEMPORARY VIEW temp pay txn stage USING org apache spar
  • 将所有输出 dll 放在 Visual Studio 的公共目录中

    我有几个不同的解决方案 其中某些项目可能依赖于其他解决方案中项目的输出 为了管理这个问题 我在构建后将 dll 文件从每个项目中的 bin 文件夹复制到共享库位置 然后将它们从那里复制 引用到依赖项目 然而 随着库解决方案变得越来越大 这往
  • 分组依据但包含“缺失”值

    假设我有以下内容 select case when fcompany Acme then Red when fcompany Acme Rockets then Blue else Green end Color sum fann sale
  • python 有没有办法改变 get 的处理顺序? [复制]

    这个问题在这里已经有答案了 If I do def foo yield from range 0 10 yield from range 10 20 for num in foo print num 我得到一个从 0 到 19 的有序列表
  • c项目makefile多重定义错误

    这个问题是一个对应于创建的repexthis问题 在我的嵌入式 C 项目中 我有两个独立的板 我想为每个板创建两个 c 文件 master c 和 Slave c 其中包含自己的特定main 功能 我使用 stm32cumbemx 生成带有
  • 如何将 SQLite-Net 扩展与复合键一起使用

    我有以下课程 Class1 cs JsonObject MemberSerialization OptIn public class Class1 PrimaryKey JsonProperty key1 public string Key
  • 如何验证 Spring MVC @PathVariable 值?

    对于在 Spring MVC 中实现的简单 RESTful JSON api 我可以使用 Bean 验证 JSR 303 来验证传递到处理程序方法中的路径变量吗 例如 RequestMapping value number customer
  • 匿名对象方法的Javadoc

    正确且有用地记录匿名对象函数的最佳方法是什么 我正在使用 Soar 进行一些编程 APIhere 并具有如下所示的代码 return handler that does blah public static RhsFunctionInter
  • 在java中将二维数组转换为List?

    I have am X n对象的二维数组说Foo 所以我有Foo foosArray 将其转换为的最佳方法是什么List
  • 空意图选择器(没有应用程序可以执行此操作)

    我的意图选择器基于白名单 只有部分应用程序会显示在意图选择器中 该代码基于另一个相反的代码 将应用程序列入黑名单 我从那里得到了该代码here and this是与之相关的相关讨论 如何创建选择器的上下文 String whitelist