2010-10-02 8 views
0

В моем приложении у меня есть ListView, когда пользователь нажимает на элемент, выполняется какое-то действие. Теперь я хочу создать контекстное меню для элемента списка с возможностью добавления этого действия на главный экран в качестве ярлыка. Может ли кто-нибудь предложить мне ссылку или подсказку, как это сделать?Ярлык на главном экране к действию в моем приложении

ответ

0
private void createShortcut(Command command){ 
    Intent shortcutIntent = new Intent(this, FormActivity.class); 
    // As binary because OS does not know type Command 
    command.putToIntentAsXml(shortcutIntent); 
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

    Intent intent = new Intent(); 
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); 
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, command.getTitle()); 
    Parcelable iconResource = Intent 
     .ShortcutIconResource 
     .fromContext(this, R.drawable.ic_launcher); 
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource); 
    intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); 

    sendBroadcast(intent); 
} 
Смежные вопросы