我在尝试以编程方式在Android应用程序主屏幕中创建快捷方式图标时出现问题。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);
你看看这个? http://stackoverflow.com/questions/6337431/android-create-shortcuts-on-the-home-screen – Antrromet
是的,我做了,它创建应用程序后仍然关闭应用程序 –
所以当你说关闭时,所有的活动生命周期方法被调用? – nandeesh