void addShortcutToDesktop(){
Intent shortcut = new Intent(ACTION_INSTALL);
BitmapDrawable iconBitmapDrawabel = null;
// 获取应用基本信息
String label = this.getPackageName();
PackageManager packageManager = getPackageManager();
try {
iconBitmapDrawabel = (BitmapDrawable) packageManager.getApplicationIcon(label);
} catch (NameNotFoundException e) {
e.printStackTrace();
}
// 设置属性
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, label);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON, iconBitmapDrawabel.getBitmap());
// 是否允许重复创建 -- fase-->否
shortcut.putExtra("duplicate", false);
// 设置启动程序
ComponentName comp = new ComponentName(label,"." + this.getLocalClassName());
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));
sendBroadcast(shortcut);
}
Intent shortcut = new Intent(ACTION_INSTALL);
BitmapDrawable iconBitmapDrawabel = null;
// 获取应用基本信息
String label = this.getPackageName();
PackageManager packageManager = getPackageManager();
try {
iconBitmapDrawabel = (BitmapDrawable) packageManager.getApplicationIcon(label);
} catch (NameNotFoundException e) {
e.printStackTrace();
}
// 设置属性
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, label);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON, iconBitmapDrawabel.getBitmap());
// 是否允许重复创建 -- fase-->否
shortcut.putExtra("duplicate", false);
// 设置启动程序
ComponentName comp = new ComponentName(label,"." + this.getLocalClassName());
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));
sendBroadcast(shortcut);
}