当前位置: 代码迷 >> Android >> Android检查手机上是否安装了第三方软件的方法-本文以百度map为例
  详细解决方案

Android检查手机上是否安装了第三方软件的方法-本文以百度map为例

热度:37   发布时间:2016-04-28 02:47:48.0
Android检查手机上是否安装了第三方软件的方法------本文以百度地图为例

转于:http://blog.csdn.net/ljb_blog/article/details/11047655

?

---------------------------------------------------------------------------------------

?

  1. package?com.example.myapi.thirdbaidumap;??
  2. ??
  3. import?java.net.URISyntaxException;??
  4. import?java.util.ArrayList;??
  5. import?java.util.List;??
  6. ??
  7. import?android.app.Activity;??
  8. import?android.content.Context;??
  9. import?android.content.Intent;??
  10. import?android.content.pm.PackageInfo;??
  11. import?android.content.pm.PackageManager;??
  12. import?android.net.Uri;??
  13. import?android.os.Bundle;??
  14. import?android.util.Log;??
  15. import?android.view.View;??
  16. import?android.view.View.OnClickListener;??
  17. import?android.widget.Button;??
  18. ??
  19. import?com.example.myapi.R;??
  20. ??
  21. /**?
  22. ?*?测试程序跳转到第三方地图,并将数据传递过去。?
  23. [email protected]?
  24. ?*?
  25. ?*/??
  26. public?class?ThirdBaiduMapTestActivity?extends?Activity?implements?OnClickListener{??
  27. ????private?Button?btn_test;??
  28. ????@Override??
  29. ????protected?void?onCreate(Bundle?savedInstanceState)?{??
  30. ????????super.onCreate(savedInstanceState);??
  31. ????????setContentView(R.layout.thirdbaidumaptest);??
  32. ????????btn_test?=?(Button)findViewById(R.id.baidu_btn_test);??
  33. ????????btn_test.setOnClickListener(this);??
  34. ????}??
  35. ??
  36. ????@Override??
  37. ????public?void?onClick(View?v)?{??
  38. ????????switch(v.getId()){??
  39. ????????case?R.id.baidu_btn_test:??
  40. ????????????//如果已安装,??
  41. ??????????????
  42. ????????????if(isAvilible(this,"com.baidu.BaiduMap")){//传入指定应用包名??
  43. ????????????????Intent?intent?=?null;??
  44. ????????????????try?{??
  45. //????????????????????intent?=?Intent.getIntent("intent://map/direction?origin=latlng:34.264642646862,108.95108518068|name:我家&destination=大雁塔&mode=driving?ion=西安&src=yourCompanyName|yourAppName#Intent;scheme=bdapp;package=com.baidu.BaiduMap;end");??
  46. ????????????????????intent?=?Intent.getIntent("intent://map/direction?"?+??
  47. ????????????????????????????"origin=大柏树&"?+??
  48. ????????????????????????????"destination=江湾镇"?+??
  49. ????????????????????????????"&mode=driving&"?+??
  50. ????????????????????????????"region=上海市"?+??
  51. ????????????????????????????"&src=yourCompanyName|yourAppName#Intent;scheme=bdapp;package=com.baidu.BaiduMap;end");??
  52. ????????????????????startActivity(intent);?//启动调用??
  53. ????????????????}?catch?(URISyntaxException?e)?{??
  54. ????????????????????Log.e("intent",?e.getMessage());??
  55. ????????????????}??
  56. ????????????}else{//未安装??
  57. ????????????????//market为路径,id为包名??
  58. ????????????????//显示手机上所有的market商店??
  59. ????????????????Uri?uri?=?Uri.parse("market://details?id=com.baidu.BaiduMap");??
  60. ????????????????Intent?intent?=?new?Intent(Intent.ACTION_VIEW,?uri);???
  61. ????????????????startActivity(intent);???
  62. ????????????}??
  63. ????????????break;??
  64. ????????}??
  65. ????}??
  66. ????/**?
  67. ?????*?检查手机上是否安装了指定的软件?
  68. [email protected]?
  69. [email protected]:应用包名?
  70. [email protected]?
  71. ?????*/??
  72. ????private?boolean?isAvilible(Context?context,?String?packageName){???
  73. ????????//获取packagemanager???
  74. ????????final?PackageManager?packageManager?=?context.getPackageManager();??
  75. ??????//获取所有已安装程序的包信息???
  76. ????????List<PackageInfo>?packageInfos?=?packageManager.getInstalledPackages(0);??
  77. ??????//用于存储所有已安装程序的包名???
  78. ????????List<String>?packageNames?=?new?ArrayList<String>();??
  79. ????????//从pinfo中将包名字逐一取出,压入pName?list中???
  80. ????????if(packageInfos?!=?null){???
  81. ????????????for(int?i?=?0;?i?<?packageInfos.size();?i++){???
  82. ????????????????String?packName?=?packageInfos.get(i).packageName;???
  83. ????????????????packageNames.add(packName);???
  84. ????????????}???
  85. ????????}???
  86. ??????//判断packageNames中是否有目标程序的包名,有TRUE,没有FALSE???
  87. ????????return?packageNames.contains(packageName);??
  88. ??}???
  89. ??
  90. } ?
  相关解决方案