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 创建快捷方式图标
  2. Android命令行启动程序正确使用技巧解析
  3. Android 程序优化
  4. 电子书 android高薪之路-android程序员面试宝典.pdf
  5. Android应用程序基础知识
  6. 详解android应用程序的反编译
  7. 高焕堂《android从程序员到架构师之路》 YY讲坛活动直面架构设计

随机推荐

  1. 解决:Error: Could not find gradle wrapp
  2. Activity的启动模式(android:launchMode)
  3. WebKit – WebKit For Android
  4. Ubuntu 16.04环境下使用Clion 2019.1.4 g
  5. How to decompile Google Android(安卓).
  6. Android遍历文件Listfile返回值为null问
  7. Ue4.20 安卓开发配置及Android(安卓)Stud
  8. android之style样式-EditText样式
  9. 关于Android(安卓)LOG系统
  10. Android(安卓)uevent