1. /**
  2. *创建快捷方式到Shortcut列表<br>
  3. *关联程序的<intent-filter>中添加:<actionandroid:name="android.intent.action.CREATE_SHORTCUT"/>
  4. */
  5. privatevoidaddShortcutToOptions(){
  6. Intentshortcut=newIntent(Intent.ACTION_CREATE_SHORTCUT);
  7. //不允许重建
  8. shortcut.putExtra("duplicate",false);
  9. //设置名字
  10. shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,
  11. this.getString(R.string.app_name));
  12. //设置图标
  13. shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
  14. Intent.ShortcutIconResource.fromContext(this,
  15. R.drawable.ic_launcher));
  16. //设置意图和快捷方式关联的程序
  17. shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
  18. newIntent(this,this.getClass()));
  19. //发送消息队列
  20. setResult(RESULT_OK,shortcut);
  21. }
  22. /**
  23. *添加快捷方式到桌面要点:
  24. *1.给Intent指定action="com.android.launcher.INSTALL_SHORTCUT"
  25. *2.给定义为Intent.EXTRA_SHORTCUT_INENT的Intent设置与安装时一致的action(必须要有)
  26. *3.添加权限:com.android.launcher.permission.INSTALL_SHORTCUT
  27. */
  28. privatevoidaddShortcutToDesktop(){
  29. Intentshortcut=newIntent("com.android.launcher.action.INSTALL_SHORTCUT");
  30. //不允许重建
  31. shortcut.putExtra("duplicate",false);
  32. //设置名字
  33. shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,this.getString(R.string.app_name));
  34. //设置图标
  35. shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutIconResource.fromContext(this,
  36. R.drawable.ic_launcher));
  37. //设置意图和快捷方式关联程序
  38. shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT,newIntent(this,this.getClass()).setAction(Intent.ACTION_MAIN));
  39. //发送消息
  40. sendBroadcast(shortcut);
  41. }
  42. /**
  43. *添加权限:<uses-permissionandroid:name="com.android.launcher.permission.READ_SETTINGS"/>
  44. *
  45. *@return
  46. */
  47. privatebooleanhasInstallShortcut(){
  48. booleanhasInstall=false;
  49. finalStringAUTHORITY="com.android.launcher.settings";
  50. UriCONTENT_URI=Uri.parse("content://"+AUTHORITY
  51. +"/favorites?notify=true");
  52. Cursorcursor=this.getContentResolver().query(CONTENT_URI,
  53. newString[]{"title","iconResource"},"title=?",
  54. newString[]{this.getString(R.string.app_name)},null);
  55. if(cursor!=null&&cursor.getCount()>0){
  56. hasInstall=true;
  57. }
  58. returnhasInstall;
  59. }

更多相关文章

  1. android studio多渠道号,多包名打包
  2. 页面跳转采用滑动效果
  3. 设置可见和隐藏
  4. android dialog style属性设置
  5. Android(安卓)网络链接,不要忘记添加网络权限。
  6. android 让自己的app成为launcher
  7. Android添加横线和竖线分割界面
  8. Android(安卓)解析Html
  9. Android(安卓)如何设置网关和路由

随机推荐

  1. MySQL中你可能忽略的COLLATION实例详解
  2. MySql新手入门的基本操作汇总
  3. 浅谈mysql执行过程以及顺序
  4. mysql 8.0.24版本安装配置方法图文教程
  5. MySQL 如何分析查询性能
  6. mysql 8.0.24 安装配置方法图文教程
  7. 如何用Navicat操作MySQL
  8. MySQL EXPLAIN输出列的详细解释
  9. MySQL 分页查询的优化技巧
  10. MySql学习笔记之事务隔离级别详解