java - 如何在自定义启动器中支持快捷方式固定?
问题描述
我正在制作自己的 Android 启动器,我想对来自其他应用程序的请求做出反应,以向主屏幕添加快捷方式。
到目前为止,我只能发现,应用程序必须通过从 ShortcutManager 调用 isRequestPinShortcutSupported() 来检查是否支持快捷方式固定,然后通过调用 requestPinShortcut() 发送请求 - 但我如何实现另一面呢?
我不知道如何告诉 ShortcutManager 我的启动器想要接收这些请求以及在哪里处理它们。我试过注册各种广播接收器,但这还不够。
我能找到的唯一有用的是 LauncherApps.PinItemRequest,它可以从 Intent 创建,但我找不到如何接收这个 Intent。
解决方案
好的,我不得不为此研究 android 源代码,但我发现我需要创建一个这样的 Activity:
<activity android:name=".Activities.AddShortcutActivity">
<intent-filter>
<action android:name="android.content.pm.action.CONFIRM_PIN_SHORTCUT" />
</intent-filter>
</activity>
然后在那个 Activity 的 onCreate() 中我可以调用
LauncherApps().getPinItemRequest( this.getIntent() );
//handle request...
this.finish();
并根据该请求做我需要的任何事情。希望这可以帮助某人。
推荐阅读
- servicenow - 我现在如何在服务上使用密码重置 REST API?
- c - 通过将指针整数和 sizeof(int) 相乘来使用 realloc 不起作用
- python - 如何仅对 numpy 数组中的一个值进行操作?(或更好的方法)
- javascript - Javascript用另一个元素数组过滤一个数组
- c# - 蓝牙 BLE 电池电量 - C#
- python - Python在Windows下找不到MEEP包
- android - 在 android 应用中使用 Facebook 登录不会调用 onCompleted() 方法?
- java - 类构造函数还是静态对象返回方法?
- cassandra - cassandra 数据建模中的嵌套地图
- java - Jhipster jdl-generation后如何将H2数据库重置为原始状态?