문제

In my app I have a ListView when user click on an item some action is performed. Now I want to make a context menu for list item with possibility to add this action to home screen as a shortcut. Could somebody offer me some link or a hint how to do this?

도움이 되었습니까?

해결책

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