android加ShortCut之历险记
2015-06-17 17:21
447 查看
需要在主入口外再加一个快捷方式,平常的加快捷方式代码很常见,一搜一大把,现在贡献下。让同学们少一点奔劳。
代码如下:
然后,调用 addShortcut,在桌面上生成了好看的图标。高兴的点一点,完蛋,提示“程序未安装”,什么意思,命名安装了吧,只是另一个
快捷方式而已。很无奈。
还好我们是unix下的java程序猿,我们知道看log.打开idea的log栏目,然后点击,我们搜素到这么一个日志。
解决:
随之google下,记得是google,不是百度啊。
在stackoverflow里找到一个这么答案。
讲targetVersion降级到19,就ok。
试试。果然搞定。
另一种思路,记得58同城也这么干过,在主启动图标外,另外搞了一个叫生活工具箱的启动图标。对58程序进行分析,在另起的shortcut工具箱配置里发现这句。
代码如下:
private void addShortcut() { // 安装的Intent Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); // 快捷名称 shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name_alias)); shortcut.putExtra("duplicate", false); Intent shortcutIntent = new Intent(Intent.ACTION_MAIN); shortcutIntent.setClassName(this.getPackageName(), this.getPackageName()+"."+"SafeBoxActivity"); shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); // 快捷图标 Intent.ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon2); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes); // 发送广播 sendBroadcast(shortcut); }在AndroidMainifest.xml中添加:
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"></uses-permission> <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"></uses-permission>
然后,调用 addShortcut,在桌面上生成了好看的图标。高兴的点一点,完蛋,提示“程序未安装”,什么意思,命名安装了吧,只是另一个
快捷方式而已。很无奈。
还好我们是unix下的java程序猿,我们知道看log.打开idea的log栏目,然后点击,我们搜素到这么一个日志。
Make sure to create a MAIN intent-filter for the corresponding activity or use the exported attribute for this activity. tag=ShortcutInfo
Launcher does not have the permission to launch Intent
解决:
随之google下,记得是google,不是百度啊。
在stackoverflow里找到一个这么答案。
讲targetVersion降级到19,就ok。
<uses-sdk android:minSdkVersion="8" tools:ignore="UsesMinSdkAttributes" android:targetSdkVersion="19"/>
试试。果然搞定。
另一种思路,记得58同城也这么干过,在主启动图标外,另外搞了一个叫生活工具箱的启动图标。对58程序进行分析,在另起的shortcut工具箱配置里发现这句。
<activity android:configChanges="locale|keyboardHidden" android:name="com.wuba.plugins.ThirdFolderActivity" android:screenOrientation="portrait" android:taskAffinity="com.wuba.affinity_third_folder" android:theme="@style/DialogActivity"> <intent-filter> <action android:name="android.intent.action.VIEW"/> <action android:name="android.intent.action.MAIN"/> </intent-filter> </activity>原来是这样啊,如果设置了这个filter,可以在原有shortcut外,再赋予一个启动另一个包里activity的能力。照样加个,问题解决。
相关文章推荐
- Android Binder驱动程序
- Android 基础
- Android调试笔记
- Android学习笔记——ProgressBar
- 第二章:Android之NDK配置与简单使用
- [Android问答] px、dp和sp,这些单位有什么区别?
- Android学习 9-> 表格布局TableLayout和网格布局GridLayout
- Android双向滑动菜单完全解析,教你如何一分钟实现双向滑动特效
- Android学习笔记——Handler(二)
- Android滑动菜单特效实现,仿人人客户端侧滑效果,史上最简单的侧滑实现
- Android照片墙完整版,完美结合LruCache和DiskLruCache
- [安卓]Android onTouch事件解析
- android 监听数据库ContentObserver使用说明
- android webview配合Html5数据操作
- android myclass
- android开发环境搭建
- androidstudio使用指南(持续更新)
- Android5.0最新特性一览,看看有没有你需要的
- Android DiskLruCache完全解析,硬盘缓存的最佳方案
- Android基础知识_Activity生命周期