解决方法
发送INSTALL_SHORTCUT广播与产生的Intent作为额外的(在这种情况下,结果Intent直接打开一些活动).
//where this is a context (e.g. your current activity) final Intent shortcutIntent = new Intent(this,SomeActivity.class); final Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,shortcutIntent); // Sets the custom shortcut's title intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,getString(R.string.app_name)); // Set the custom shortcut icon intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutIconResource.fromContext(this,R.drawable.icon)); // add the shortcut intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); sendBroadcast(intent);
您的清单还需要此权限:
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />