android快捷方式shortcut 管理

如下58同城快捷方式的效果:



下面是添加桌面快捷方式:

/**
	 * 启动某个activity是需要在manifest里面定义 <intent-filter> <action
	 * android:name="android.intent.action.MAIN" /> </intent-filter>
	 */
	private void addShortCut()
	{
		// 安装的Intent
		Intent shortcut =
				new Intent("com.android.launcher.action.INSTALL_SHORTCUT");

		// 快捷名称
		shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "家居");
		// 快捷图标是允许重复
		shortcut.putExtra("duplicate", false);

		Intent shortcutIntent = new Intent();
		shortcutIntent.putExtra("tName", "家居");
		// shortcutIntent.setClass(mContext, HouseJjActivity.class);
		shortcutIntent.setClassName("com.shangc.houseproperty",
				"com.shangc.houseproperty.ui.activity.TestActivity");
		shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);

		// 快捷图标
		ShortcutIconResource iconRes =
				Intent.ShortcutIconResource.fromContext(mContext,
						R.drawable.ic_launcher);
		shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
		// 发送广播
		mContext.sendBroadcast(shortcut);
	}

通过图标启动一个半透明的activity,在这个activity管理小工具什么的。上面注释标红的很重要....刚开始弄了好久都不行,提示应用未安装什么的错误。

当然记得加权限:

<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
    <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />

半透明的activity很简单了.....

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值