如下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很简单了.....