diff --git a/common/src/main/java/com/yunbao/common/utils/GoogleUtils.java b/common/src/main/java/com/yunbao/common/utils/GoogleUtils.java index d1e89d8a7..f47191f74 100644 --- a/common/src/main/java/com/yunbao/common/utils/GoogleUtils.java +++ b/common/src/main/java/com/yunbao/common/utils/GoogleUtils.java @@ -174,6 +174,19 @@ public class GoogleUtils { } } + public boolean getGoogleService() { + boolean flag; + try { + Class clz = mActivity.getClassLoader().loadClass("com.shayu.lib_google.utils.GoogleBillingManage"); + googlePay = clz.getConstructor(Activity.class).newInstance(mActivity); + flag = (boolean) googlePay.getClass().getMethod("getGoogleService").invoke(googlePay); + } catch (Exception e) { + throw new RuntimeException(e); + } + return flag; + } + + public void setFirebaseTokenListener(Activity activity, FirebaseTokenListener firebaseTokenListener) { Timer timer = new Timer(); TimerTask task = new TimerTask() { diff --git a/common/src/main/java/com/yunbao/common/views/APKUpdateCustomPopup.java b/common/src/main/java/com/yunbao/common/views/APKUpdateCustomPopup.java index 35d8a444c..b433c3957 100644 --- a/common/src/main/java/com/yunbao/common/views/APKUpdateCustomPopup.java +++ b/common/src/main/java/com/yunbao/common/views/APKUpdateCustomPopup.java @@ -3,6 +3,7 @@ package com.yunbao.common.views; import android.app.Activity; import android.content.Context; import android.content.Intent; +import android.content.pm.PackageManager; import android.net.Uri; import android.os.Build; import android.os.Handler; @@ -114,7 +115,7 @@ public class APKUpdateCustomPopup extends CenterPopupView { } else if (CommonAppConfig.IS_GOOGLE_PLAY == 2) { //华为 //todo - launchAppDetail(mContext, "com.pdlive.shayu", "com.pdlive.shayu"); + launchAppDetail(mContext, "com.pdlive.shayu", "com.huawei.appmarket"); } else { versionImmediateUse.setVisibility(GONE); updateLine.setVisibility(VISIBLE); @@ -129,19 +130,31 @@ public class APKUpdateCustomPopup extends CenterPopupView { }); } + public static boolean isAppStoreExist(Context context) { + try { + PackageManager packageManager = context.getPackageManager(); + packageManager.getPackageInfo("com.huawei.appmarket", PackageManager.GET_ACTIVITIES); + return true; + } catch (PackageManager.NameNotFoundException e) { + return false; + } + } + + public static void launchAppDetail(Context mContext, String appPkg, String marketPkg) { try { if (TextUtils.isEmpty(appPkg)) { return; } - - Uri uri = Uri.parse("market://details?id=" + appPkg); - Intent intent = new Intent(Intent.ACTION_VIEW, uri); - if (!TextUtils.isEmpty(marketPkg)) { - intent.setPackage(marketPkg); + if (isAppStoreExist(mContext)) { + Uri uri = Uri.parse("appmarket://details?id=" + appPkg); + Intent intent = new Intent(Intent.ACTION_VIEW, uri); + if (!TextUtils.isEmpty(marketPkg)) { + intent.setPackage(marketPkg); + } + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + mContext.startActivity(intent); } - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - mContext.startActivity(intent); } catch (Exception e) { e.printStackTrace(); } diff --git a/lib_google/src/main/java/com/shayu/lib_google/utils/GoogleBillingManage.java b/lib_google/src/main/java/com/shayu/lib_google/utils/GoogleBillingManage.java index dfd43d032..ed6c73a2b 100644 --- a/lib_google/src/main/java/com/shayu/lib_google/utils/GoogleBillingManage.java +++ b/lib_google/src/main/java/com/shayu/lib_google/utils/GoogleBillingManage.java @@ -20,6 +20,7 @@ import com.android.billingclient.api.SkuDetails; import com.android.billingclient.api.SkuDetailsParams; import com.android.billingclient.api.SkuDetailsResponseListener; import com.google.android.gms.ads.identifier.AdvertisingIdClient; +import com.google.android.gms.common.GoogleApiAvailability; import com.google.android.gms.common.GooglePlayServicesNotAvailableException; import com.google.android.gms.common.GooglePlayServicesRepairableException; @@ -28,11 +29,8 @@ import org.json.JSONException; import org.json.JSONObject; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; -import java.util.Map; /** * 新写Google内付工具类做简单的封装 @@ -201,6 +199,11 @@ public class GoogleBillingManage implements PurchasesUpdatedListener { } } + public boolean getGoogleService() { + int code = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(mContext); + return code == 0; + } + int resultCode = -1; String resultToken = ""; String resultOrderId = ""; diff --git a/main/src/main/java/com/yunbao/main/activity/GoogleFragment.java b/main/src/main/java/com/yunbao/main/activity/GoogleFragment.java index 9b03293ea..877896605 100644 --- a/main/src/main/java/com/yunbao/main/activity/GoogleFragment.java +++ b/main/src/main/java/com/yunbao/main/activity/GoogleFragment.java @@ -17,8 +17,6 @@ import android.webkit.WebView; import androidx.fragment.app.Fragment; import com.facebook.appevents.AppEventsConstants; -import com.google.android.gms.common.ConnectionResult; -import com.google.android.gms.common.GoogleApiAvailability; import com.yunbao.common.http.CommonHttpUtil; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.utils.GoogleUtils; @@ -47,7 +45,6 @@ public class GoogleFragment extends Fragment { public GoogleFragment() { } - @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //通过参数中的布局填充获取对应布局 @@ -64,9 +61,10 @@ public class GoogleFragment extends Fragment { Log.e("ttt", url); rlWebview.loadUrl(url); + googleUtils = new GoogleUtils(getActivity()); + // 验证是否已在此设备上安装并启用Google Play服务,以及此设备上安装的旧版本是否为此客户端所需的版本 - int code = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(getActivity()); - if (code == ConnectionResult.SUCCESS) { + if (googleUtils.getGoogleService()) { isGoogleService = true; // 支持Google服务 initGooglePay();