gpt4 book ai didi

java - 如何多次购买 Google Play 产品?

转载 作者:搜寻专家 更新时间:2023-11-01 09:34:44 24 4
gpt4 key购买 nike

我只能购买一件商品(“productitem1”)。如果我购买了该商品,我将无法再次购买。但我需要它来多次购买。在我的 Google Play 控制台中,我只能在“托管应用内产品”和“订阅”之间进行选择。我已将其设置为“托管应用内产品”。

@Override
protected void onActivityResult(int request, int response, Intent data) {
if (request == 42) {
int responseCode = data.getIntExtra("RESPONSE_CODE", 0);
String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
String dataSignature = data.getStringExtra("INAPP_DATE_SIGNATURE");
if (response == RESULT_OK) {
try {
JSONObject jo = new JSONObject(purchaseData);
String productId = jo.getString("productId");
Toast.makeText(this, "OK", Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
Log.e(getClass().getSimpleName(), "JSONException", e);
}
}
}
}

btnBuy.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final String name = "productitem1";
try {
Bundle buyIntentBundle = mService.getBuyIntent(3, getPackageName(), name, "inapp", "");
if(buyIntentBundle.getInt("RESPONSE_CODE")==0) {
PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
startIntentSenderForResult(
pendingIntent.getIntentSender(), 42, new Intent(), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
}
} catch (Exception e) {
Log.e(Start.this.getClass().getSimpleName(),"Exception:",e);
}

}
});

最佳答案

在购买具有相同 SKU 的另一件商品之前,您需要使用 In-App Billing API 提供的方法之一消费它,例如 IabHelper.consumeAsync()

mHelper.consumeAsync(inventory.getPurchase(SKU_ITEM), mConsumeFinishedListener);

IabHelper.OnConsumeFinishedListener mConsumeFinishedListener =
new IabHelper.OnConsumeFinishedListener() {
public void onConsumeFinished(Purchase purchase, IabResult result) {
if (result.isSuccess()) {
// provision the in-app purchase to the user
// (for example, credit 50 gold coins to player's character)
} else {
// handle error
}
}
};

更多信息在这里:https://developer.android.com/training/in-app-billing/purchase-iab-products.html#Consume

关于java - 如何多次购买 Google Play 产品?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44287080/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com