Android之添加快捷方式(Shortcut)到手机桌面

455 阅读1分钟

在两个手机上测试,发现小米手机上添加了快捷方式后不能移除,三星手机可以。权限

  要在手机桌面上添加快捷方式,首先需要在manifest中添加权限。

 

    <!-- 添加快捷方式 -->
    <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
    <!-- 移除快捷方式 -->
    <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
    <!-- 查询快捷方式 -->
    <uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" />

 

添加快捷方式

 

  添加快捷方式,是向桌面应用(launcher)发送相关action的广播,相关的action如下:

public static final String ACTION_ADD_SHORTCUT = "com.android.launcher.action.INSTALL_SHORTCUT";