部分代码:
private void shortCut(){ Intent intent = new Intent(); intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); intent.putExtra("duplicate", false); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "hello");//标题 Intent.ShortcutIconResource sr = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);//自定义图标 intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, sr); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(this, this.getClass())); this.sendBroadcast(intent); }
权限配置:
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>