2010-10-02 91 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); 
} 
相关问题