プログラムで Android アプリのホーム画面にショートカット アイコンを作成しようとしたときに問題が発生しました。
ショートカットアイコンを作成できましたが、その後、「アプリケーションのショートカットが作成されました」というアラートが表示され、アプリケーションが閉じます。アプリケーションを閉じたくありません。可能であれば、ショートカットを作成した後にポップアップするアラートを取り除きたいです。
どうすればそれを達成できますか?
これが私の現在のコードです:
Intent targetIntent = new Intent (Intent.ACTION_MAIN);
targetIntent.setClassName (getApplicationContext(), "com.mainListActivity");
Intent shortcutintent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
shortcutintent.addFlags(Intent.FLAG_FROM_BACKGROUND);
//repeat to create is forbidden
shortcutintent.putExtra("duplicate", false);
//set the name of shortCut
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME,"SecureLauncher");
//set icon
Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher_cloud);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
//set the application to lunch when you click the icon
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,targetIntent);
sendBroadcast(shortcutintent);