google计费问题

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

这是我第一次就stackoverflow和一件小事寻求帮助。我当然缺乏理解它的基本知识。如何在handlepurchase(billingclient,purchase)中获得billingclient?提前感谢您的回复

public class Billing {

    private Context context;
    private List<String> skuList;

    ' COSTRUTTORE'
    public Billing(Context context, List<String> skuList) {
        this.context = context;
        this.skuList = skuList;
    }

    ' INTERFACCIA CALLBACK '
    public interface Callback{
        void onSkuDetailsList(BillingClient billingClient, List<SkuDetails> skuDetailsList);
        void onResponse(Purchase purchase);
        void onError();
    }

    public void MyPurchase(final Callback callback) {

        PurchasesUpdatedListener purchaseUpdateListener = new PurchasesUpdatedListener() {

            @Override
            public void onPurchasesUpdated(BillingResult billingResult, List<Purchase> purchases) {

                if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && purchases != null) {

                    for (Purchase purchase : purchases) {

                        callback.onResponse(purchase);
                        handlePurchase(billingClient, purchase);

                    }

                } else {

                    callback.onError();

                }

            }

        };

        final BillingClient billingClient = BillingClient.newBuilder(context).enablePendingPurchases().setListener(purchaseUpdateListener).build();

    }

    static void handlePurchase(BillingClient billingClient, Purchase purchase) {

    }

}
mwngjboj

mwngjboj1#

在顶部添加计费客户端。。。

public class Billing {

    private Context context;
    private List<String> skuList;
    private Billing client;

更换

final BillingClient billingClient = BillingClient.newBuilder(context).enablePendingPurchases().setListener(purchaseUpdateListener).build();

billingClient = BillingClient.newBuilder(context).enablePendingPurchases().setListener(purchaseUpdateListener).build();

现在billingclient将在

static void handlePurchase( Purchase purchase) {
  //
  billingClient...
    }

相关问题