代码如下:

写道 /**
* 创建快捷方式
*/
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(安卓)PackageManager 卸载包的方法
  2. Android(安卓)查看本机外网IP
  3. android 应用程序使用统计
  4. Android开关机代码
  5. Ijkplayer视频播放
  6. Android代码实现APK文件的安装与卸载
  7. Android中通过代码检测系统是否有root权限
  8. android基于AndPermission的权限申请封装类
  9. android 显示 网络图片

随机推荐

  1. 所谓的沉浸式状态栏
  2. 一个不错的loading效果
  3. 移植SlidingMenu Android(安卓)library,和
  4. Eclipse中插件(Google Android)插件
  5. 带你彻底理解 Window 和 WindowManager
  6. ListView适配器--ArrayAdapter
  7. Android(安卓)JNI .h头文件生成说明
  8. 模态对话框 和 非模态对话框
  9. Activity跳转动画
  10. [记录]Navigation无title注意事项