|
|
@@ -0,0 +1,91 @@
|
|
|
+package com.mgtech.base_library.util;
|
|
|
+
|
|
|
+import android.content.Context;
|
|
|
+import android.content.Intent;
|
|
|
+import android.content.pm.PackageInfo;
|
|
|
+import android.content.pm.PackageManager;
|
|
|
+import android.net.Uri;
|
|
|
+
|
|
|
+import com.mgtech.base_library.R;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import static com.mgtech.base_library.contextUtil.ContextUtils.getContext;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @ProjectName: BaseLibrary
|
|
|
+ * @Package: com.mgtech.base_library.util
|
|
|
+ * @ClassName: OpenExternalAppUtil
|
|
|
+ * @Description: 打开第三方APP
|
|
|
+ * @Author: niusongtao
|
|
|
+ * @CreateDate: 2020/9/27 13:54
|
|
|
+ * @UpdateUser: 更新者:niusongtao
|
|
|
+ * @UpdateDate: 2020/9/27 13:54
|
|
|
+ * @UpdateRemark: 更新说明:
|
|
|
+ * @Version: 1.0
|
|
|
+ */
|
|
|
+public class OpenExternalAppUtil {
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @method startNavigationGoogle
|
|
|
+ * @description 谷歌地图导航,起点就是定位点
|
|
|
+ * @date: 2020/9/27 13:57
|
|
|
+ * @author: niusongtao
|
|
|
+ * @param latitude, longitude
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public static Intent startNavigationGoogle(double latitude , double longitude) {
|
|
|
+ if (isAvailable(getContext(), "com.google.android.apps.maps")) {
|
|
|
+ Uri gmmIntentUri = Uri.parse("google.navigation:q=" + latitude + "," + longitude);
|
|
|
+ Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
|
|
|
+ mapIntent.setPackage("com.google.android.apps.maps");
|
|
|
+ return mapIntent;
|
|
|
+ }
|
|
|
+ ToastUtils.showShort(R.string.have_no_google_map);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @method startNavigationGoogle
|
|
|
+ * @description 打开WhatsApp
|
|
|
+ * @date: 2020/9/27 13:57
|
|
|
+ * @author: niusongtao
|
|
|
+ * @param
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public static Intent startWhatsApp() {
|
|
|
+ if (isAvailable(getContext(), "com.whatsapp")) {
|
|
|
+ Intent sendIntent = new Intent();
|
|
|
+ sendIntent.setAction(Intent.ACTION_SEND);
|
|
|
+ sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
|
|
|
+ sendIntent.setType("text/plain");
|
|
|
+ sendIntent.setPackage("com.whatsapp");//区别别的应用包名
|
|
|
+ return sendIntent;
|
|
|
+ }
|
|
|
+ ToastUtils.showShort(R.string.have_no_whats_app);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //验证各种导航地图是否安装
|
|
|
+ public static boolean isAvailable(Context context, String packageName) {
|
|
|
+ //PackageManager
|
|
|
+ final PackageManager packageManager = context.getPackageManager();
|
|
|
+ //获取所有已安装程序的包信息
|
|
|
+ List<PackageInfo> packageInfoList = packageManager.getInstalledPackages(0);
|
|
|
+ //用于存储所有已安装程序的包名
|
|
|
+ List<String> packageNames = new ArrayList<String>();
|
|
|
+ //从packageInfoList中将包名字逐一取出,压入pName list中
|
|
|
+ if (packageInfoList != null) {
|
|
|
+ for (int i = 0; i < packageInfoList.size(); i++) {
|
|
|
+ String packName = packageInfoList.get(i).packageName;
|
|
|
+ packageNames.add(packName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断packageNames中是否有目标程序的包名,有TRUE,没有FALSE
|
|
|
+ return packageNames.contains(packageName);
|
|
|
+ }
|
|
|
+}
|