用户应用订阅InAppPurchases时是否有任何回调?

时间:2020-07-10 20:25:11

标签: android google-play

我已经按照官方指南实施了订阅流程。但是,当用户在Google Api一侧确认订阅信息时,是否可以获得订阅信息?因为这里是空的,没有任何回报。如何获得该交易的访问权限?

private void startConnection(String type) {

        //Call newBuilder() to create an instance of BillingClient You must also call setListener()
        //passing a reference to a PurchasesUpdatedListener to receive updates on purchases initiated
        // by your app, as well as those initiated by the Google Play Store.
        BillingClient billingClient = BillingClient.newBuilder(this).enablePendingPurchases().setListener(this).build();

        billingClient.isFeatureSupported(BillingClient.FeatureType.SUBSCRIPTIONS);
        billingClient.isFeatureSupported(BillingClient.FeatureType.SUBSCRIPTIONS_UPDATE);
        //Establish a connection to Google Play. The setup process is asynchronous, and you must
        //implement a BillingClientStateListener to receive a callback once the setup of the client
        //is complete and it’s ready to make further requests.

        billingClient.startConnection(new BillingClientStateListener() {
            @Override
            public void onBillingSetupFinished(BillingResult billingResult) {
                String s = billingResult.getDebugMessage();
                String ss = String.valueOf(billingResult.getResponseCode());
                if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
                    //specifies a list of product ID strings and a SkuType
                    List<String> skuList = new ArrayList<>();
                    skuList.add(type);
//                    skuList.add("vip");
                    SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
                    //IMPORTANT The SkuType can be either SkuType.INAPP for one-time products or SkuType.SUBS for subscriptions
                    params.setSkusList(skuList).setType(BillingClient.SkuType.SUBS);
                    billingClient.querySkuDetailsAsync(params.build(),
                            new SkuDetailsResponseListener() {
                                @Override
                                public void onSkuDetailsResponse(BillingResult billingResult,
                                                                 List<SkuDetails> skuDetailsList) {
                                    // Process the result.
                                    //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.
                                    if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && skuDetailsList != null) {
                                        for (SkuDetails skuDetails : skuDetailsList) {
                                            String sku = skuDetails.getSku();
                                            String price = skuDetails.getPrice();
                                            BillingFlowParams flowParams = BillingFlowParams.newBuilder()
                                                    .setSkuDetails(skuDetailsList.get(0))
                                                    .build();
                                            billingClient.launchBillingFlow(RewardVideoActivity.this, flowParams);
                                        }
                                    }


                                }
                            });
                }
            }

            @Override
            public void onBillingServiceDisconnected() {
                String s = "error";
                // Try to restart the connection on the next request to
                // Google Play by calling the startConnection() method.
            }
        });
    }

1 个答案:

答案 0 :(得分:0)

回叫结果来自接口PurchasesUpdatedListener的实现

onPurchasesUpdated(BillingResult billingResult, List<Purchase> list)

相关问题