私のアプリのアクションへのホーム画面のショートカット

StackOverflow https://stackoverflow.com/questions/3847109

  •  27-09-2019
  •  | 
  •  

質問

私のアプリには、ユーザーがアイテムをクリックすると、いくつかのアクションが実行されます。次に、このアクションをショートカットとしてホーム画面に追加する可能性を備えたリストアイテムのコンテキストメニューを作成したいと思います。誰かが私にこれを行う方法やヒントを提供してくれますか?

役に立ちましたか?

解決

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