代码如下:

写道 /**
* 创建快捷方式
*/
private void createShortCut() {

Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "创建快捷方式");
shortcut.putExtra("duplicate", false); // 不允许重复
ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this,R.drawable.icon);// 设置快捷方式的图标
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
// 定义shortcut点击事件
String action = "com.android.action.test";
Intent respondIntent = new Intent(this, this.getClass());
respondIntent.setAction(action);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, respondIntent);

sendBroadcast(shortcut);

}

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

卸载快捷方式:

写道 /**
* 卸载快捷方式
*/
void deleteShortcut() {
Intent shortcut = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT");
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "卸载快捷方式"); //指定要卸载的快捷方式的名称
String action = "com.android.action.test";
String appClass = this.getPackageName() + "." + this.getLocalClassName();
ComponentName comp = new ComponentName(this.getPackageName(), appClass);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(action).setComponent(comp));

sendBroadcast(shortcut);

} 需要权限:<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />

更多相关文章

  1. Android创建快捷方式图标
  2. android基于AndPermission的权限申请封装类
  3. Android 10 文件读写权限申请
  4. android 6.0权限全面详细分析和解决方案
  5. 运行时权限解析以及申请的实现(可完美解决java.lang.SecurityExce
  6. 转载:Android 获取ROOT权限原理解析

随机推荐

  1. Android 之 Gallery画廊用法
  2. Binder解析
  3. Android MediaRecorder录制音频
  4. android shape的用法总结
  5. android布局属性详解分享
  6. Android布局属性一览表
  7. Android控件属性手册
  8. Android users-permission权限列表
  9. Android之使用ContentResolver对通信录中
  10. Android单例模式