[置顶]手机APP创建桌面快捷方式
2016-07-27 22:37
337 查看
预览:
需要权限:
1 <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
配置文件:AndroidManifest.xml
在应用的闪屏页面Activity的 oncreate方法调用 installShortcut();
代码:
常量工具类GlobalConstantsUtils:
1 public static final String PREF_IS_SHORTCUT_INTALLED = "is_shortcut_intalled";// 是否已经创建快捷方式
1 public static final String ACTION_HOME = "com.myself.news.ACTION_HOME";// 跳转到主页面的ACTION
需要权限:
1 <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
配置文件:AndroidManifest.xml
1 <activity 2 android:name="com.myself.news.activity.GuideActivity" 3 android:label="@string/title_activity_guide" > 4 <intent-filter> 5 <action android:name="com.myself.news.ACTION_HOME" /> 6 7 <category android:name="android.intent.category.DEFAULT" /> 8 </intent-filter> 9 </activity>
在应用的闪屏页面Activity的 oncreate方法调用 installShortcut();
代码:
1 // 创建快捷方式 2 // com.android.launcher.permission.INSTALL_SHORTCUT 3 private void installShortcut() { 4 // 判断有没有创建过快捷方式 5 boolean isCreated = SharedPreferencesUtils.getBoolean(this, 6 GlobalConstantsUtils.PREF_IS_SHORTCUT_INTALLED, false); 7 // 判断是否已经创建过 8 if (!isCreated) { 9 // 发广播 10 Intent intent = new Intent(); 11 intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); 12 13 // 图标 14 // 根据资源文件id生成Bitmap对象 15 intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapFactory 16 .decodeResource(getResources(), R.drawable.ic_launcher)); 17 // 名称 18 intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "手机安全卫士"); 19 20 // 动作 21 Intent actionIntent = new Intent(); 22 // 跳到主页面 23 actionIntent.setAction(GlobalConstantsUtils.ACTION_HOME); 24 25 intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, actionIntent); 26 sendBroadcast(intent); 27 28 // 标记已经创建过快捷方式,下次不再创建 29 SharedPreferencesUtils.setBoolean(this, 30 GlobalConstantsUtils.PREF_IS_SHORTCUT_INTALLED, true); 31 } 32 }
常量工具类GlobalConstantsUtils:
1 public static final String PREF_IS_SHORTCUT_INTALLED = "is_shortcut_intalled";// 是否已经创建快捷方式
1 public static final String ACTION_HOME = "com.myself.news.ACTION_HOME";// 跳转到主页面的ACTION
相关文章推荐
- [置顶]android 四大组件之---Service
- WWDC2016 Session笔记 - Xcode 8 Auto Layout新特性
- Android 对对话框进行监听
- Android自定义搜索时的关键字气泡动画-原理详解
- 变量和常量
- Android Studio中关联SVN进行版本控制(二)从已有的SVN库中checkout代码到AS(本地)中
- LINE最新版6.5.0在iOS上的删除信息取证
- ViewPager无限循环滑动无卡顿,详解OnPageChangeListener
- iOS --- 自定义navigationBar的两种常见方式
- 微信授权验证
- iOS--Masonry解决 tableViewCell 重用时约束冲突
- 提升Android Studio的Gradle构建速度
- Android项目配置gitignore 的方法
- Android Studio中获取SHA1或MD5的方法
- [置顶] Android带你实现门票布局效果
- Android 属性动画(Property Animation) 完全解析 (下)
- Android 属性动画(Property Animation) 完全解析 (上)
- 设置Button背景色与点击涟漪颜色(5.0+)
- 使用cocos2d-android做最简单的飞机大战
- Android Zxing二维码扫描图片拉伸、扫描框过小、扫描框扩大后(或不拉伸后)闪退问题