代码如下:
写道
/**
* 创建快捷方式
*/
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);
}
android 代码创建快捷方式
原创
©著作权归作者所有:来自51CTO博客作者wx6392e1a0991de的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
删除 Windows 设备和驱动器中的WPS网盘、百度网盘等快捷图标
在安装诸如WPS软件、某度云盘、爱奇艺等客户端后,Windows 的“我的电脑”(或“此电脑”)中的“设备和驱动器”部分会出现对应的软件图标。这种情况被许多技术人员视为不必要的干扰,因此许多用户想要知道如何隐藏或删除这些图标。
删除Windows设驱动器 删除我的电脑WPS网盘 删除我的电脑百度网盘 删除我的电脑爱奇艺 删除我的电脑中无用图标 -
将任务栏图标设置为只显示小图标
任务栏图标修改
任务栏 小图标 -
创建显示桌面快捷图标
<br />说起来,“显示桌面”这个东东,别看不起眼,却是一个提高工作效率的宝贝哦。丢了它非常不方便。于是我就想ommand=ToggleDe
command windows shell 工具 工作