在我的应用我有当一个项目的用户点击执行一些动作一个ListView。 现在,我想为列表项目上下文菜单的可能性增加这个动作的主屏幕为快捷方式。 可能有人给我提供一些链接或提示如何做到这一点?

有帮助吗?

解决方案

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);
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top