2

我正在使用这个 tuto 将 Play Billing Library 集成到我的应用程序中:http ://www.androidrey.com/implement-play-billing-library-in-android-application/一切都很好......好吧,不是全部。我很难知道何时取消订阅,我测试了所有方法以找到一个 resultCode 或了解此状态的东西,但是有一个我无法实现的方法。可能是这个问题吗?

类:BillingManager.java

public void queryPurchases() {
    Runnable queryToExecute = new Runnable() {
        @Override
        public void run() {
            long time = System.currentTimeMillis();
            Purchase.PurchasesResult purchasesResult = billingClient.queryPurchases(BillingClient.SkuType.INAPP);
            if (areSubscriptionsSupported()) {
                Purchase.PurchasesResult subscriptionResult
                        = billingClient.queryPurchases(BillingClient.SkuType.SUBS);
                System.out.println("QUERY 0");
                if (subscriptionResult.getResponseCode() == BillingClient.BillingResponse.OK) {
                    purchasesResult.getPurchasesList().addAll(
                            subscriptionResult.getPurchasesList());
                    System.out.println("QUERY 1");
                } else {
                    // Handle any error response codes.
                }
            } else if (purchasesResult.getResponseCode() == BillingClient.BillingResponse.OK) {
                // Skip subscription purchases query as they are not supported.
                System.out.println("QUERY 2");
            } else {
                // Handle any other error response codes.
                System.out.println("QUERY 3");
            }
            onQueryPurchasesFinished(purchasesResult);
            System.out.println("QUERY RESULT "+ purchasesResult);
        }
    };

    executeServiceRequest(queryToExecute);
}

private void onQueryPurchasesFinished(Purchase.PurchasesResult result) {
    // Have we been disposed of in the meantime? If so, or bad result code, then quit
    if (billingClient == null || result.getResponseCode() != BillingClient.BillingResponse.OK) {
        Log.w(TAG, "Billing client was null or result code (" + result.getResponseCode()
                + ") was bad – quitting");
        return;
    }

    Log.d(TAG, "Query inventory was successful.");

    // Update the UI and purchases inventory with new list of purchases
    // mPurchases.clear();
    onPurchasesUpdated(BillingClient.BillingResponse.OK, result.getPurchasesList());
}

public boolean areSubscriptionsSupported() {
    int responseCode = billingClient.isFeatureSupported(BillingClient.FeatureType.SUBSCRIPTIONS);
    if (responseCode != BillingClient.BillingResponse.OK) {
        Log.w(TAG, "areSubscriptionsSupported() got an error response: " + responseCode);
    }
    return responseCode == BillingClient.BillingResponse.OK;
}

它应该在这里调用:MyBillingUpdateListener.java

public class MyBillingUpdateListener implements BillingManager.BillingUpdatesListener {
//final BillingManager billingManager = new BillingManager(,this );

@Override
public void onBillingClientSetupFinished() {
    //billingManager.queryPurchases(); THIS IS WHAT I COULD NOT IMPLEMENT 
}

欢迎任何帮助,谢谢!

4

1 回答 1

1

Play Billing 1.0 没有购买状态的概念(不再),因此目前无法使用 Play Billing 库获取此信息。我的理解是queryPurchases应该只返回实际有效的购买。但是,它从长期存在的缓存中获取信息,您无法手动更新它。

onBillingClientSetupFinished是完全无关的。

这是关于该主题的积极讨论:https ://github.com/googlesamples/android-play-billing/issues/122

于 2018-04-05T23:57:13.463 回答