Google In App Billing中的BillingFlowParams无法使用真实的sku开始biling

时间:2019-01-20 13:37:03

标签: in-app-purchase in-app-billing android-billing in-app-subscription play-billing-library

我已经编写了这些代码,这些代码可以确保从api中获取skus,因为它会在获取的skus日志中记录其打印,但是当我使用 .setSku()设置sku时。 setType()或什至直接 .setSkuDetails()仍未建立billingFlowParams,但是当我将 android.test.purchased 传递给 .setSku()。我听错了,我做错了。任何帮助都会得到申请。

SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder()

    List<String> Skus=new ArrayList<>();
    Skus.add("sms_100103");
    Skus.add("sms_500105");
    params.setSkusList(Skus).setType(BillingClient.SkuType.INAPP);
    mBillingClient.querySkuDetailsAsync(params.build(), new SkuDetailsResponseListener() {
        @Override
        public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
            Log.d(TAG, "onSkuDetailsResponse: "+responseCode+" 1."+skuDetailsList.get(1));
            BillingFlowParams flowParams = BillingFlowParams.newBuilder()
                    .setSku(skuDetailsList.get(1).getSku())
                    .setType(skuDetailsList.get(1).getType())
                    .build();
          int res=  mBillingClient.launchBillingFlow((Activity) context,flowParams);
            Log.d(TAG, "onSkuDetailsResponse: "+res);
        }
    });

1 个答案:

答案 0 :(得分:2)

代码现已更改:

public void attemptPurchase(String skuID){
SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
List<String> Skus=new ArrayList<>();
Skus.add(skuID);
params.setSkusList(Skus).setType(BillingClient.SkuType.SUBS);
billingClient.querySkuDetailsAsync(params.build(), (billingResult, list) -> {
    Log.d(TAG, "onSkuDetailsResponse: "+billingResult.getResponseCode()+" 1."+list.toString());
    BillingFlowParams flowParams = BillingFlowParams.newBuilder()
            .setSkuDetails( list.get( 0 ) )
            .build();
    BillingResult responseCode = billingClient.launchBillingFlow(this, flowParams);
} );
}