android设置app快捷方式

时间:2011-03-09 08:37:32

标签: android shortcut

我想知道是否可以(如果是,我该怎么办)在用户屏幕上自动添加我的应用程序的快捷方式。例如,当我从我的应用程序按下按钮时,在用户屏幕上自动设置快捷方式。

谢谢!

2 个答案:

答案 0 :(得分:0)

我不认为这是可能的,但原来是:adding shortcut to homescreenLauncherShortcut from the API demos很酷

答案 1 :(得分:0)

试试这个:

private void addShortcut() {

    Intent addIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    addIntent.putExtra("duplicate", false);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getResources().getString(R.string.hello_world));
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(getApplicationContext(),
                    R.drawable.ic_action_search));
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(getApplicationContext(),OtherActivity.class));
    getApplicationContext().sendBroadcast(addIntent);
}

并且您还需要清单中的一些权限,例如:

<uses-permission 
        android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission 
        android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
相关问题