为android studio设置应用内购买时遇到问题

yfjy0ee7  于 2021-07-03  发布在  Java
关注(0)|答案(1)|浏览(416)

在androidstudio中设置应用内购买真的很困难,下面是代码和logcat。

BillingClient billingClient = BillingClient.newBuilder(AdditionalSupport.this)
            .setListener(purchasesUpdateListener)
            .enablePendingPurchases()
            .build();

    billingClient.startConnection(new BillingClientStateListener() {
        @Override
        public void onBillingSetupFinished(BillingResult billingResult) {

            if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {

                List<String> skuList = new ArrayList<>();
                skuList.add("one_time_purchase");
                skuList.add("two_time_purchase");
                SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
                params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP);
                Log.d(TAG, "onBillingSetupFinished: sku list" + skuList);

                billingClient.querySkuDetailsAsync(params.build(), new SkuDetailsResponseListener() {
                    @Override
                    public void onSkuDetailsResponse(BillingResult billingResult, List<SkuDetails> skuDetailsList) {
                        Log.d(TAG, "onBillingSetupFinished: query billing " + billingResult.getResponseCode());

                        if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
                            Log.d(TAG, "onBillingSetupFinished: query finished " + skuDetailsList);

                            for (SkuDetails skuDetails : skuDetailsList) {
                                Log.d(TAG, "onBillingSetupFinished: query sku " + skuDetails);
                                BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder()
                                        .setSkuDetails(skuDetails)
                                        .build();

                                int responseCode = billingClient.launchBillingFlow(AdditionalSupport.this, billingFlowParams).getResponseCode();
                                Log.d(TAG, "onBillingSetupFinished: query finished " + responseCode);

                            }
                        }
                    }
                });
            }
        }

关键logcat条目:
附加支持:onbillingsetupfinished:sku列表[一次购买,两次购买]附加支持:onbillingsetupfinished:query billing 0附加支持:onbillingsetupfinished:query finished[]
因此,帐单响应代码为0或ok,但skudetailslist为空。我原以为skudetailslist从skulist获得了信息,然后将其传递到params变量中。有人知道我做错了什么吗?或者,如果你知道任何关于android应用内购买的好教程,如果你能给我指一下,我将非常感激。
非常感谢。

2nc8po8w

2nc8po8w1#

终于解决了。
你所要做的就是将应用程序上传到play商店,假设你已经将一些应用程序内的购买信息加载到你的play帐户上,它就会工作。

相关问题