anddroid程序创建桌面快捷键

 
 
权限:
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />

代码:
/**
* 创建桌面快捷方式
*/
private void createShortCut() {
Intent shortcut = new Intent(
"com.android.launcher.action.INSTALL_SHORTCUT");
// 快捷方式的名称
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,
getString(R.string.app_name));
// 不允许重复创建
shortcut.putExtra("duplicate", false);
// 指定快捷方式的启动对象
ComponentName comp = new ComponentName(this.getPackageName(),
this.getLocalClassName());
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(
Intent.ACTION_MAIN).setComponent(comp));
// 快捷方式的图标
ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(
this, R.drawable.icon);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
// 发出广播
sendBroadcast(shortcut);
}

猜你喜欢

转载自blog.csdn.net/niuba123456/article/details/48047669