我是新手,正尝试首次实现内购。
我正在使用Google Play内购库。 https://developer.android.com/google/play/billing/billing_library_overview
我想要实现可消耗性的内购。我正在使用“android.test.purchased”保留ID进行测试。我可以成功加载skuDetails并进行购买,也可以成功消费购买。
这是我的handlePurchase方法,其中包含consumeAsync。
void handlePurchase(Purchase purchase) {
BillingClient client = BillingClient.newBuilder(NewAdActivity.this)
.enablePendingPurchases()
.setListener(this)
.build();
if (purchase.getPurchaseState() == Purchase.PurchaseState.PURCHASED) {
System.out.println("item successfully purchased");
if (!purchase.isAcknowledged()) {
ConsumeParams consumeParams = ConsumeParams.newBuilder()
.setPurchaseToken(purchase.getPurchaseToken())
.setDeveloperPayload(purchase.getDeveloperPayload())
.build();
ConsumeResponseListener consumeResponseListener = new ConsumeResponseListener() {
@Override
public void onConsumeResponse(BillingResult billingResult, String purchaseToken) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && purchaseToken != null) {
System.out.println("SUCCESSFULLY consumed PURCHASE");
providecontent();
}
else {
System.out.println("FAILED TO consume:”);
}
}
};
client.consumeAsync(consumeParams, consumeResponseListener);
}
}
}
当我消耗购买时,它是否也会承认购买?我需要手动设置“acknowledged”:true在purchase.originalJson中吗?
我的代码是否正确消费了购买的物品?或者在消费物品之前我需要单独包含 acknowledgePurchase 功能。
请回复。非常感谢任何帮助。
谢谢。