Android 为应用创建、删除桌面快捷方式

本文介绍了两种在Android上为应用创建桌面快捷方式的方法:一是程序启动时主动添加,二是用户通过长按桌面被动添加。主动添加需要在AndroidManifest.xml中声明权限,而被动添加同样涉及权限设置。同时提供了权限添加的详细步骤和一个demo的下载链接。
摘要由CSDN通过智能技术生成

为应用创建快捷方式目前有两种方法:

1. 程序启动时主动添加快捷方式到桌面------------>主动添加

2.长按桌面,弹出应用选择窗,拖动应用到桌面---------->被动添加


公用方法:

/**

	  * 返回添加到桌面快捷方式的Intent:  

	  * 1.给Intent指定action="com.android.launcher.INSTALL_SHORTCUT"

	  * 2.给定义为Intent.EXTRA_SHORTCUT_INENT的Intent设置与安装时一致的action(必须要有)  

	  * 3.添加权限:com.android.launcher.permission.INSTALL_SHORTCUT

	  */

	 public static Intent getShortcutToDesktopIntent(Context context) {
		 Intent intent = new Intent(); 
		 intent.setClass(context, context.getClass());  
        /*以下两句是为了在卸载应用的时候同时删除桌面快捷方式*/
		 intent.setAction("android.intent.action.MAIN");  
		 intent.addCategory("android.intent.category.LAUNCHER");  
        
	     Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
	     // 不允许重建
	     shortcut.putExtra("duplicate", false);
	     // 设置名字
	     sho
  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值