星空网 > 软件开发 > 操作系统

手机APP创建桌面快捷方式

 

 

预览:手机APP创建桌面快捷方式images/loading.gif' data-original="http://images2015.cnblogs.com/blog/885821/201604/885821-20160417234329082-115228287.png" />

 

需要权限:

   1 <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" /> 

 

配置文件:AndroidManifest.

1 <activity2       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, BitmapFactory16           .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 

 




原标题:手机APP创建桌面快捷方式

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

安卓国内用tiktok解决方案:https://www.goluckyvip.com/tag/82580.html
怎样能看tiktok:https://www.goluckyvip.com/tag/82581.html
tiktok shop academy:https://www.goluckyvip.com/tag/82583.html
tiktok带货分佣:https://www.goluckyvip.com/tag/82584.html
tiktok wallpaper:https://www.goluckyvip.com/tag/82585.html
tiktok带货门槛:https://www.goluckyvip.com/tag/82586.html
美国版权小知识-哪些作品能够登记美国版权?:https://www.kjdsnews.com/a/1836627.html
俄罗斯汽车企业进口东风汽车零部件组装雪铁龙汽车:https://www.kjdsnews.com/a/1836628.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流