我正在使用此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
}
欢迎任何帮助,谢谢!
最佳答案
Play Billing 1.0不再具有购买状态的概念,因此当前无法使用Play Billing库获取此信息。
我的理解是queryPurchases
应该只返回实际的有效购买。但是,它从寿命长的缓存中获取信息,并且您无法手动更新它。onBillingClientSetupFinished
完全无关。
这是一个关于该主题的积极讨论:https://github.com/googlesamples/android-play-billing/issues/122
关于android - 知道何时取消订阅-Play Billing 1.0,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49637797/