Android创建快捷方式(shortcut)

Java代码 private static final String ACTION_INSTALL_SHORTCUT = "com.Android.launcher.action.INSTALL_SHORTCUT";

Java代码 Intent shortcutIntent = new Intent(ACTION_INSTALL_SHORTCUT);

‍shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME,  getString(R.string.app_name));

‍shortcutIntent.putExtra(EXTRA_SHORTCUT_DUPLICATE, false);

Intent intent = new Intent();

intent.setComponent(new ComponentName(this.getPackageName(),  ".Splash"));

shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);

shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.icon));

sendBroadcast(shortcutIntent);

Uses permission

Xml代码 <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/> 

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwsfww.html