作为一名Android开发者 不仅要精通国内的相关框架,还应该熟练使用国外相关框架
比如支付功能,国内支付宝 微信支付对接已经是有很成熟的相关文档了
但是对接google支付就不一样的 牵涉到集成 测试问题
今天我们就来说所谷歌支付相关坑、
首先需要依赖jJAR包:
implementation 'com.android.billingclient:billing-ktx:5.1.0'
然后是相关支付代码
public class BillingWrapper { private PayListern mpaylistenr; private static final String TAG = "BillingWrapper"; private static final int STATE_NULL = 0; private BillingClient billingClient; private String toPurchaseSkuId = ""; private Activity mActivity = null; private static BillingWrapper _instance = null; public static BillingWrapper getInstance() { if (_instance == null) { _instance = new BillingWrapper(); } return _instance; } public void InitBilling(@NonNull Activity activity,String id,PayListern payListern) { mActivity = activity; toPurchaseSkuId= id; mpaylistenr=payListern; billingClient = BillingClient.newBuilder(activity) .setListener(new PurchasesUpdatedListener() { @Override public void onPurchasesUpdated(@NonNull BillingResult billingResult, @Nullable List<Purchase> list) { int code = billingResult.getResponseCode(); String msg = billingResult.getDebugMessage(); Log.e(TAG, "onPurchasesUpdated:code = " + c