InApp购买响应正常但不显示Dialog

问题描述 投票:0回答:1

问题是在InApp Purchase的实现过程中,单击按钮,响应结果正常,但是没有出现购买对话框这里是代码

 //To query Google Play for in-app product details, call this method
    mBillingClient.querySkuDetailsAsync(params.build(),
            new SkuDetailsResponseListener() {
                @Override
                public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
                    Log.d(TAG, "response from query -> " + responseCode);
                    if (responseCode == BillingClient.BillingResponse.OK
                            && skuDetailsList != null) {
                        for (SkuDetails skuDetails : skuDetailsList) {
                            String sku = skuDetails.getSku();
                            String price = skuDetails.getPrice();
                            if ("minimum".equals(sku)) {
                                //Retrieving a product’s price is an important step before
                                // a user can purchase a product because the price is different
                                // for each user based on their country of origin.
                                mOneDollarPurchasePrice = price;
                                BillingFlowParams flowParams = BillingFlowParams.newBuilder()
                                        .setSkuDetails(skuDetails)
                                        .build();
                                responseCode = mBillingClient.launchBillingFlow(ShopActivity.this, flowParams);
                            } else  {
                                //TODO Handle other scenarios of SKU
                            }
                        }
android in-app-purchase in-app-billing
1个回答
0
投票

您必须在购买后使用该产品。

  private void consumeFromLibrary() {
    ConsumeResponseListener listener = new ConsumeResponseListener() {
        @Override
        public void onConsumeResponse(@BillingClient.BillingResponse int responseCode, String outToken) {
            Log.d(TAG, "Consume response -> " + responseCode);
            if (responseCode == BillingClient.BillingResponse.OK) {
                // Handle the success of the consume operation.
                // For example, increase the number of coins inside the user's basket.
            } else if (responseCode == BillingClient.BillingResponse.SERVICE_DISCONNECTED) {
                Log.d(TAG, "SERVICE DISCONNECTED");

            }
        }
    };
    Purchase.PurchasesResult purchasesResult = mBillingClient.queryPurchases(BillingClient.SkuType.INAPP);
    List<Purchase> purchaseList = purchasesResult.getPurchasesList();
    for (Purchase purchase : purchaseList) {
        mBillingClient.consumeAsync(purchase.getPurchaseToken(), listener);
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.