Android创建桌面快捷方式
在桌面上创建特定界面的快捷入口,icon和title根据请求参数命名。在网上收集的一些相关资 料,在使用intent发送广播的时候,一些型号的收集会有问题,如魅族MX,红米,以及华为,使用setClass和setComponent创建快捷 方式的时候不能正确生成快捷方式,有的快捷方式的会使用相应包下的APP名称命名,有的手机如魅族会应为包名冲突而无法创建快捷方式。解决的办法就是使用 setAction来创建Intent,然后可以在data/data/com.andoird.launcher/databases /launcher.db中查看桌面快捷方式的数据是否正确。以下是相关代码:
Intent intent = new Intent("cn.example.action.SHORTCUT");
//自定义action
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
Bundle bundle = new Bundle();
bundle.putString("type", "default");
intent.putExtras(bundle);
//创建快捷方式的Intent
Intent shortcutintent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
//不允许重复创建
shortcutintent.putExtra("duplicate", false);
//需要现实的名称
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "快捷方式");
//快捷图片
Parcelable icon = Intent.ShortcutIconResource.fromContext(activity.getApplicationContext() , R.drawable.logo);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
//点击快捷图片,运行的程序主入口
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
//发送广播。OK
activity.sendBroadcast(shortcutintent);
然后在快捷启动对应的activity下加上intent-filter:
<intent-filter>
<action android:name="cn.kuwo.player.action.SHORTCUT" />
</intent-filter>
这样就可以适应大多数机型
相关文章
- Android系统自带的android.util.Base64的实现源码
- 修改Android手机内核,绕过反调试
- uniapp - 简单的方式生成app证书(android和ios)
- Android Binder的原理与使用
- 【Android】保存Fragment切换状态
- 使用Maven构建Android项目
- Android Studio软件技术基础 —Android项目描述---1-类的概念-android studio 组件属性-+标志-Android Studio 连接真机不识别其他途径
- android常见错误-The container 'Android Dependencies' references non existing library
- Android studio的错误:radle sync failed: Cause: failed to find target android-21 :
- 《精通Android 实例开发》——第1章,第1.7节使用CMD方式创建Android虚拟设备
- Android JNI学习(三)——Java与Native相互调用
- 基于 Android NDK 的学习之旅-----Java 调用C
- HashMap在Android和Java中的不同实现
- Android studio 怎么使用单元测试(不需要device)
- android 开发不能创建目录
- Android Jetpack-ViewModel
- 物联网平台搭建的全过程介绍(五)——基于阿里云物联网平台的Android聊天app源码
- Android App开发超实用实例 | jQuery Mobile在Android手机上创建图文结合的导航按钮
- Android学习之Menu显示图标,同时不覆盖ToolBar的方法
- Android 编辑框(EditText)属性学习
- Unity Android 之 应用签名发布 Publishing Settings 中创建和自定义 keystore 的简单方法(内附说明和操作步骤)
- Android Studio 基础 之 如何取消使用 Android X 的操作(附有详细步骤)
- 大约Android远程监控APP源代码