创建安卓桌面快捷图标
2015-08-30 17:06
281 查看
在欢迎界面延迟几秒后调用
SharedPreferences setting = getSharedPreferences("silent.preferences", 0);
// 判断是否第一次启动应用程序(默认为true)
boolean firstStart = setting.getBoolean("FIRST_START", true);
// 第一次启动时创建桌面快捷方式
if (firstStart) {
Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
// 快捷方式的名称
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
// 不允许重复创建
shortcut.putExtra("duplicate", false);
// 指定快捷方式的启动对象
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT,new Intent(this, this.getClass()).setAction(Intent.ACTION_MAIN));
// 快捷方式的图标
Intent.ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
// 发出广播
sendBroadcast(shortcut);
// 将第一次启动的标识设置为false
SharedPreferences.Editor editor = setting.edit();
editor.putBoolean("FIRST_START", false);
// 提交设置
editor.commit();
}
SharedPreferences setting = getSharedPreferences("silent.preferences", 0);
// 判断是否第一次启动应用程序(默认为true)
boolean firstStart = setting.getBoolean("FIRST_START", true);
// 第一次启动时创建桌面快捷方式
if (firstStart) {
Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
// 快捷方式的名称
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
// 不允许重复创建
shortcut.putExtra("duplicate", false);
// 指定快捷方式的启动对象
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT,new Intent(this, this.getClass()).setAction(Intent.ACTION_MAIN));
// 快捷方式的图标
Intent.ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
// 发出广播
sendBroadcast(shortcut);
// 将第一次启动的标识设置为false
SharedPreferences.Editor editor = setting.edit();
editor.putBoolean("FIRST_START", false);
// 提交设置
editor.commit();
}
相关文章推荐
- TestLink基本流程
- io知识点总结第一篇
- 半同步/半反应堆模型(使用线程池)的TCP服务器例子
- .NET程序的性能要领和优化建议
- eclipse 终极操作技巧
- (转)如何提高单片机抗干扰
- Android Drawable系列(1):自定义背景以及注意事项
- MOOC中国接受《环球时报》英文版专访:MOOC证书对求职有用吗?
- java常用API知识点总结
- 解决maven项目update project更改项目编码的问题
- a different object with the same identifier value was already associated with the session:
- 杜绝返回函数内局部变量的指针或引用
- 自定义Adapter的listview(很重要)
- openwrt 端口回流的关键
- 面试题30.最小的k个数
- C99标准支持结构体按成员名称进行指定初始化。
- 数组知识点
- 通过/dev/mem实现用户层访问GPIO寄存器
- 正则表达式
- HttpSession