首页 > 解决方案 > 如何在自定义启动器中支持快捷方式固定?

问题描述

我正在制作自己的 Android 启动器,我想对来自其他应用程序的请求做出反应,以向主屏幕添加快捷方式。

到目前为止,我只能发现,应用程序必须通过从 ShortcutManager 调用 isRequestPinShortcutSupported() 来检查是否支持快捷方式固定,然后通过调用 requestPinShortcut() 发送请求 - 但我如何实现另一面呢?

我不知道如何告诉 ShortcutManager 我的启动器想要接收这些请求以及在哪里处理它们。我试过注册各种广播接收器,但这还不够。

我能找到的唯一有用的是 LauncherApps.PinItemRequest,它可以从 Intent 创建,但我找不到如何接收这个 Intent。

标签: javaandroidandroid-launcherhomescreenandroid-shortcut

解决方案


好的,我不得不为此研究 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();

并根据该请求做我需要的任何事情。希望这可以帮助某人。


推荐阅读