由网友(冷漠的眼神)分享简介:创建快捷方式打开应用程序时,但问题是,创建一个快捷方式总是开放的应用程序,如果我打开然后应用程序20时创建的快捷方式20 我需要的只是创建一个快捷方式,首开不保护无效的onCreate(包savedInstanceState){super.onCreate(savedInstanceState);的setContent...
创建快捷方式打开应用程序时,但问题是,创建一个快捷方式总是开放的应用程序,如果我打开然后应用程序20时创建的快捷方式20
我需要的只是创建一个快捷方式,首开不
保护无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
ShortcutIcon();
}
私人无效ShortcutIcon(){
意图shortcutIntent =新的意图(getApplicationContext(),Main.class);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
意图addIntent =新意图();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME,WhatsApp的Imagenes);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutIconResource.fromContext(getApplicationContext(),R.drawable.icono));
addIntent.setAction(com.android.launcher.action.INSTALL_SHORTCUT);
。getApplicationContext()sendBroadcast(addIntent);
}
解决方案
在pre-JB的Android版本,你可以试试这个:
addIntent.putExtra(重复,假);
另外,你可以卸载并重新安装快捷方式:
intent.setAction(com.android.launcher.action.UNINSTALL_SHORTCUT);
。getApplicationContext()sendBroadcast(意向);
intent.setAction(com.android.launcher.action.INSTALL_SHORTCUT);
。getApplicationContext()sendBroadcast(意向);
更多信息here.
I create shortcut when open the app but the problem is that create a shortcut always that open the app if I open the app 20 time then creates 20 shortcuts
I need that only create one shortcut the first open not more
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ShortcutIcon();
}
private void ShortcutIcon(){
Intent shortcutIntent = new Intent(getApplicationContext(), Main.class);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Whatsapp Imagenes");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.icono));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);
}
解决方案
On pre-JB android versions, you can try this:
addIntent.putExtra("duplicate", false);
Otherwise, you can just uninstall and reinstall the shortcut:
intent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(intent);
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(intent);
More info here.
相关推荐
最新文章