ich ziemlich viel Zeit damit verbracht haben auf verschiedenen Lösungen von Stackoverflow versucht, aber die meisten von ihnen sind nutzlos, weil Sie starten neue Instanzen von Aktivität. Ich brauche Abkürzung, die genau wie die in App-Liste arbeitet oder einen automatisch von Google Play installiert (Aktivität beginnen oder bereits begonnen Aktivität nach vorne bringen).
@Override
public void onCreate(Bundle savedInstanceState) {
//Save the flag to SharedPreferences to prevent duplicated shortcuts
if (!settings.isShortcutAdded()) {
addShortcut();
settings.setShortcutAdded(true);
}
}
private void addShortcut() {
Intent shortcutIntent = new Intent(getApplicationContext(), MainActivity.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
shortcutIntent.addCategory(Intent.CATEGORY_LAUNCHER);
int flags = Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT;
shortcutIntent.addFlags(flags);
Intent addIntent = new Intent();
addIntent.putExtra("duplicate", false);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getResources().getString(R.string.app_name));
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource
.fromContext(getApplicationContext(), R.drawable.ic_launcher));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);
}
Und vergessen Sie nicht, Ihr Manifest zu aktualisieren:
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
Ich glaube nicht die APIs, die Funktionalität aus. Im Pull-Up-Dialogfeld wird standardmäßig ein App-Symbol angezeigt. –