在桌面添加快捷方式
在桌面添加快捷方式
/**
* 在桌面添加快捷方式
* @param icon 快捷方式图标
* @param name 快捷方式名称
* @param url 快捷方式的intent url
*/
private void addShortcut(Parcelable icon, String name, String url){
try {
// Intent intentAddShortcut = new Intent(Intent.ACTION_CREATE_SHORTCUT);
Intent intentAddShortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
//添加名称
intentAddShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
//添加图标
intentAddShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
//设置Launcher的Uri数据
Intent intentLauncher = new Intent();
intentLauncher.setAction("android.intent.action.VIEW");
Uri content_url = Uri.parse(url);
intentLauncher.setData(content_url);
//添加快捷方式的启动方法
intentAddShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intentLauncher);
sendBroadcast(intentAddShortcut);
} catch (Exception e) {
LogUtil.e(tag, e);
}
}

浙公网安备 33010602011771号