çoğu, çünkü işe yaramaz Faaliyetlerin yeni örneklerini başlatıyorlar. Uygulama listesindeki veya Google Play tarafından otomatik olarak yüklenen (tam olarak etkinliğe başla veya etkinliğe önceden Etkinleştir'i getir) olan kısayollara ihtiyacım var.
@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);
}
Ve bildirim güncellemek için unutma:
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
Ben apis bu işlevselliği maruz sanmıyorum. Varsayılan olarak çekme iletişim kutusunda bir uygulama simgesi alırsınız. –