2011-03-09 52 views
1

我想知道是否有可能(如果是,我該怎麼做)在用戶屏幕上自動添加我的應用程序的快捷方式。例如,當我按下我應用程序中的按鈕時,自動在用戶屏幕上設置快捷方式。android設置應用程序快捷方式

謝謝!

回答

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); 
} 

,你也需要一些權限,在你的menifest,像這個:

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