Question

Dans mon application, j'ai un ListView lorsque l'utilisateur clique sur un élément est une action réalisée. Maintenant, je veux faire un menu contextuel pour l'élément de liste avec possibilité d'ajouter cette action à l'écran d'accueil comme un raccourci. Pourrait offrir à quelqu'un moi un peu de lien ou un indice comment faire?

Était-ce utile?

La solution

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);
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top