Android程序开发之手机APP创建桌面快捷方式
更新时间:2016年04月18日 09:15:38 作者:Jusenr/荣雪-rongsnow
这篇文章主要介绍了Android程序开发之手机APP创建桌面快捷方式 的相关资料,需要的朋友可以参考下
预览效果图:

需要权限:
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
配置文件:AndroidManifest.xml
<activity android:name="com.myself.news.activity.GuideActivity" android:label="@string/title_activity_guide" > <intent-filter> <action android:name="com.myself.news.ACTION_HOME" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>
在应用的闪屏页面Activity的 oncreate方法调用 installShortcut();
代码:
// 创建快捷方式
// com.android.launcher.permission.INSTALL_SHORTCUT
private void installShortcut() {
// 判断有没有创建过快捷方式
boolean isCreated = SharedPreferencesUtils.getBoolean(this,
GlobalConstantsUtils.PREF_IS_SHORTCUT_INTALLED, false);
// 判断是否已经创建过
if (!isCreated) {
// 发广播
Intent intent = new Intent();
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
// 图标
// 根据资源文件id生成Bitmap对象
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapFactory
.decodeResource(getResources(), R.drawable.ic_launcher));
// 名称
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "手机安全卫士");
// 动作
Intent actionIntent = new Intent();
// 跳到主页面
actionIntent.setAction(GlobalConstantsUtils.ACTION_HOME);
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, actionIntent);
sendBroadcast(intent);
// 标记已经创建过快捷方式,下次不再创建
SharedPreferencesUtils.setBoolean(this,
GlobalConstantsUtils.PREF_IS_SHORTCUT_INTALLED, true);
}
}
常量工具类GlobalConstantsUtils:
public static final String PREF_IS_SHORTCUT_INTALLED = "is_shortcut_intalled";// 是否已经创建快捷方式 public static final String ACTION_HOME = "com.myself.news.ACTION_HOME";// 跳转到主页面的ACTION
相关文章
Android启动初始化方案App StartUp的应用详解
这篇文章主要介绍了Android启动初始化方案App StartUp的使用方法,StartUp是为了App的启动提供的一套简单、高效的初始化方案,下面我们来详细了解2022-09-09
Android开发之图形图像与动画(一)Paint和Canvas类学习
Paint类代表画笔,用来描述图形的颜色和风格,如线宽,颜色,透明度和填充效果等信息;Canvas类代表画布,通过该类提供的构造方法,可以绘制各种图形;感兴趣的朋友可以了解下啊,希望本文对你有所帮助2013-01-01
Android Recyclerview实现多选,单选,全选,反选,批量删除的功能
本篇文章主要介绍了Android Recyclerview 实现多选,单选,全选,反选,批量删除的功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2017-06-06


最新评论