添加快捷方式
private void addShortcut(String name) {
// 设置关联程序
Intent launcherIntent = new Intent(this, SplashActivity.class);
launcherIntent.setAction(Intent.ACTION_MAIN);
launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Intent addShortcutIntent = new Intent();
addShortcutIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
// 不允许重复创建
addShortcutIntent.putExtra("duplicate", false);
// 名字
addShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
// 图标
addShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(SplashActivity.this,
R.drawable.icon));
addShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launcherIntent);
// 发送广播
sendBroadcast(addShortcutIntent);
}
不要忘了在manifest中添加权限哦
<!-- 添加快捷方式 -->
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<!-- 移除快捷方式 -->
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
<!-- 查询快捷方式 -->
<uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" />
这样程序在第一次运行的时候会自动创建快捷方式,以后每次启动的时候会提示已创建快捷方式,这样会觉得很烦,所以我在程序中做了下面的操作:
SharedPreferences sharedPraferences = getSharedPreferences("com.rosevision.ofashion", Context.MODE_PRIVATE);
if (sharedPraferences.getInt("addShortcut", 0) == 0) {
addShortcut(getResources().getString(R.string.app_name));
sharedPraferences.edit().putInt("addShortcut",1).apply();
}
这样处理以后,程序只有在每一次运行的时候自动创建快捷方式,以后每次启动的时候会判断是否已经创建了快捷方式,如果没有的话再去创建
分享到:
相关推荐
Android判断是否获取到桌面快捷方式权限
android系统判断快捷方式是否存在、添加删除快捷方式
类似QQ添加桌面快捷方式联系人,也可以自定义桌面图标,新手值得看看
android 检查是否创建桌面快捷方式以及创建快捷方式
android向桌面添加快捷方式的源代码,将解可以看我的博客哈。
里面的工具类是 通过 各自的实现来判断 华为,小米 oppo vivi等的应用是否 拥有快捷方式 的权限,如果没有的话,则需要去手动授权。
可以实现为手机上的某个应用添加桌面快捷方式、移除某个应用到快捷方式 如有问题,请浏览我的博客:http://blog.csdn.net/u011268102/article/details/9335971
NULL 博文链接:https://justsee.iteye.com/blog/1115247
NULL 博文链接:https://trylovecatch.iteye.com/blog/1169537
当我们想把添加快捷方式的Activity添加到这一列表时,只需要在这个Activity注册时添加一个Action为android.intent.action.CREATE_SHORTCUT的IntentFilter就可以了。 ShortCutAction类: packag
本文实例讲述了Android编程添加快捷方式(Short)到手机桌面的方法。分享给大家供大家参考,具体如下: 权限 要在手机桌面上添加快捷方式,首先需要在manifest中添加权限。 <!-- 添加快捷方式 --> <uses ...
本文实例讲述了Android添加(创建)、删除及判断是否存在桌面快捷方式的方法。分享给大家供大家参考。具体实现方法如下: /** * 判断桌面是否已添加快捷方式 * * @param cx * @param titleName * 快捷方式名称 * @...
android中在桌面上创建快捷方式源码,删除快捷方式在某些机器上会不成功,因此最好只添加不删除
shortcut快捷方式的添加删除与查询是否存在
源码参考,欢迎下载
本文实例讲述了Android编程实现向桌面添加快捷方式的方法。分享给大家供大家参考,具体如下: 有时候为了使用方便,需要在桌面上添加快捷方式,下面是两种添加快捷方式的方法: 方法1: void setshortCut() { ...
手机升级到安卓O后,突然发现创建快捷方式的功能失效了,查询一番后发现:安卓O要使用ShortcutManager来创建快捷方式。 安卓N及以下版本: Intent addShortcutIntent = new Intent...
这个是向android添加桌面图标的源代码,运行程序向android桌面添加一个桌面快捷方式,代码简洁,运行正确