直接在手机桌面上建立应用的快捷方式

来源:互联网 发布:剑灵力士女捏脸数据图 编辑:程序博客网 时间:2024/05/23 02:00

使用如下代码,即可以在桌面上建立一个应用的快捷方式:

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(), ".MainActivity"));    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 android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>


原创粉丝点击