新增判断 判断是否有google服务

This commit is contained in:
hch 2023-12-08 14:17:36 +08:00
parent d0b7b065b2
commit f8ac4617ed
3 changed files with 22 additions and 8 deletions

View File

@ -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) { public void setFirebaseTokenListener(Activity activity, FirebaseTokenListener firebaseTokenListener) {
Timer timer = new Timer(); Timer timer = new Timer();
TimerTask task = new TimerTask() { TimerTask task = new TimerTask() {

View File

@ -20,6 +20,7 @@ import com.android.billingclient.api.SkuDetails;
import com.android.billingclient.api.SkuDetailsParams; import com.android.billingclient.api.SkuDetailsParams;
import com.android.billingclient.api.SkuDetailsResponseListener; import com.android.billingclient.api.SkuDetailsResponseListener;
import com.google.android.gms.ads.identifier.AdvertisingIdClient; 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.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException; import com.google.android.gms.common.GooglePlayServicesRepairableException;
@ -28,11 +29,8 @@ import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 新写Google内付工具类做简单的封装 * 新写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; int resultCode = -1;
String resultToken = ""; String resultToken = "";
String resultOrderId = ""; String resultOrderId = "";

View File

@ -17,8 +17,6 @@ import android.webkit.WebView;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import com.facebook.appevents.AppEventsConstants; 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.CommonHttpUtil;
import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.utils.GoogleUtils; import com.yunbao.common.utils.GoogleUtils;
@ -47,7 +45,6 @@ public class GoogleFragment extends Fragment {
public GoogleFragment() { public GoogleFragment() {
} }
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//通过参数中的布局填充获取对应布局 //通过参数中的布局填充获取对应布局
@ -64,9 +61,10 @@ public class GoogleFragment extends Fragment {
Log.e("ttt", url); Log.e("ttt", url);
rlWebview.loadUrl(url); rlWebview.loadUrl(url);
googleUtils = new GoogleUtils(getActivity());
// 验证是否已在此设备上安装并启用Google Play服务以及此设备上安装的旧版本是否为此客户端所需的版本 // 验证是否已在此设备上安装并启用Google Play服务以及此设备上安装的旧版本是否为此客户端所需的版本
int code = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(getActivity()); if (googleUtils.getGoogleService()) {
if (code == ConnectionResult.SUCCESS) {
isGoogleService = true; isGoogleService = true;
// 支持Google服务 // 支持Google服务
initGooglePay(); initGooglePay();