Collegamento sulla schermata iniziale per un'azione nella mia app
-
27-09-2019 - |
Domanda
Nella mia app ho un ListView quando l'utente clicca su un elemento viene eseguita una certa azione. Ora voglio fare un menu di scelta rapida per la voce di elenco con possibilità di aggiungere questa azione alla schermata iniziale come una scorciatoia. Qualcuno potrebbe offrirmi qualche link o un suggerimento come fare questo?
Soluzione
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);
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow