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/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();