添加快捷方式
private void addShortCut(){
Intent intent=new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
intent.putExtra(intent.EXTRA_SHORTCUT_NAME,"paths");
intent.putExtra("duplicate",false);
Intent shortcutintent=new Intent(Intent.ACTION_MAIN);
shortcutintent.setClassName(this, this.getClass().getName());
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,shortcutintent );
ShortcutIconResource shortcutIconResource=new ShortcutIconResource().fromContext(this,R.drawable.composer_place);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIconResource);
sendBroadcast(intent);
}
删除快捷方式
private void deleteShortCut(){
Intent deleteShortcut=new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT");
deleteShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "paths");
String appclass=this.getPackageName()+"."+this.getLocalClassName();
ComponentName componentName=new ComponentName(this.getPackageName(),appclass);
deleteShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(componentName));
sendBroadcast(deleteShortcut);
}