How to properly update Android BillingFlowParams methods deprecated

 ̄綄美尐妖づ 提交于 2019-12-06 04:28:17

问题


I have

BillingFlowParams purchaseParams = BillingFlowParams.newBuilder().setSku(skuId).setType(billingType).setOldSkus(oldSkus).build();

but now

setSku

setType

setOldSkus

are all deprecated.

I want to update the old code without releasing an update that mess with the active and future subscriptions. How should I properly update the above code?

Currently I use a String myProduct="my_newsweek_1"; to identify the purchase and BillingClient.SkuType.SUBS to identify the type, and I simply pass null to setOldSkus

Documentation reports that

setSku (String sku) and setType (String type) have been replaced with setSkuDetails(SkuDetails) (this SkuDetails object receives only a String as parameter in the constructor and throws JSONException so seems It doesn't work with old String constants)

and

setOldSkus(ArrayList<String> oldSkus) has been replaced with setOldSku(String)


回答1:


You need BillingFlowParams for launchBillingFlow(). You can create your SkuDetails with your own json string but it is not the intended way. You should at first call querySkuDetailsAsync() and get necessary skuDetailsList and then use them for launchBillingFlow()


public void querySkuDetailsAsync(@SkuType final String itemType, final List<String> skuList, final SkuDetailsResponseListener listener) {
    Runnable queryRequest = new Runnable() {
        @Override
        public void run() {
            // Query the purchase async
            SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
            params.setSkusList(skuList).setType(itemType);
            mBillingClient.querySkuDetailsAsync(params.build(),
                    new SkuDetailsResponseListener() {
                        @Override
                        public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
                            //use skuDetails in skuDetailsList
                        }
                    });
            }
        };
    executeServiceRequest(queryRequest);
}

public void initiatePurchaseFlow(final SkuDetails skuDetails) {
   Runnable purchaseFlowRequest = new Runnable() {
      @Override
      public void run() {
      Log.d(TAG, "Launching in-app purchase flow.");
      BillingFlowParams purchaseParams = BillingFlowParams.newBuilder().setSkuDetails(skuDetails).build();
         mBillingClient.launchBillingFlow(mActivity, purchaseParams);
      }
   };
   executeServiceRequest(purchaseFlowRequest);
}


来源:https://stackoverflow.com/questions/54752757/how-to-properly-update-android-billingflowparams-methods-deprecated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!