Si prega di non farlo automaticamente !!! Lascia che l'utente scelga se vuole o meno la tua scorciatoia!
Ecco il codice necessario:
//Create shortcutIntent here with the intent that will launch you app.
Intent shortcutIntent = (...)
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
final Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
// Sets the custom shortcut's title
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,sName);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
// add the shortcut
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(intent);
Non dimenticare un permesso supplementare nel manifesto!
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
fonte
2010-07-26 08:20:15
E 'possibile farlo automaticamente quando l'utente INSTALLA l'app? – Moshik
Non ho mai sentito parlare di app avviata in Android ... È possibile eseguire questa parte di codice al primo avvio manuale dell'applicazione. –
Quello che faccio per la mia applicazione è che creo una preferenza booleana "actiondone", che è di default "false" Se (! Actiondone) allora imposto questa preferenza su true e faccio la mia azione "firstboot". Spero che tu abbia familiarità con le preferenze ... –