代码如下:

写道 /**
* 创建快捷方式
*/
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 无权限 伪造短信
  3. 21、从头学Android之Android的数据存储--SD卡
  4. android获取通知权限
  5. Android获取手机配置信息
  6. Android(安卓)M 新的运行时权限开发者需要知道的一切
  7. 怎样用 C/C++ 开发一个原生程序运行在 Android(安卓)下而不用 AD
  8. Android数据存储之文件存储
  9. 《Android安全机制解析与应用实践》笔记 第2章

随机推荐

  1. android progressbar style定义解析
  2. android 设置支持pad等大屏幕、大分辨率
  3. Android开发——控件基础(三)EditText组件
  4. Android开发你需要具备的基本功
  5. 空闲时间玩玩Andriod,你知道如何配置环境
  6. AndroidStudio安装教程(Windows环境下)
  7. android文字阴影效果设置
  8. 原生态Android操作介绍之一
  9. android 布局 px or dip
  10. Android(安卓)共享文件的 Runtime 权限