gpt4 book ai didi

安卓应用内订阅 : Inventory call returns purchase as null even if purchase exists

转载 作者:太空狗 更新时间:2023-10-29 14:15:52 27 4
gpt4 key购买 nike

这个问题与Purchased subscription not returned in inventory非常相似& Android billing - error you own this item但他们提供的答案并没有解决我的问题。

我有来自 https://code.google.com/p/marketbilling/ 的最新代码.我签名的 apk 安装在设备上,并作为草稿上传到 Play 商店。我的订阅购买存在于 Google Wallet Merchant Center 中并显示在 queryPurchases 和 queryInventoryAsync 中,但它在我的 PurchaseActivity 中显示为 null。

此代码来自 IabHelper.java 中的 queryPurchases 方法并显示购买信息:

        for (int i = 0; i < purchaseDataList.size(); ++i) {
String purchaseData = purchaseDataList.get(i);
String signature = signatureList.get(i);
String sku = ownedSkus.get(i);

logDebug("Purchase Data: "+purchaseData);

if (Security.verifyPurchase(mSignatureBase64, purchaseData, signature)) {
logDebug("Sku is owned: " + sku);
Purchase purchase = new Purchase(itemType, purchaseData, signature);

logDebug("Purchase Data: "+purchase);

if (TextUtils.isEmpty(purchase.getToken())) {
logWarn("BUG: empty/null token!");
logDebug("Purchase data: " + purchaseData);
}

// Record ownership and token
inv.addPurchase(purchase);

logDebug("Get Purchase Data: "+ inv.getPurchase(sku));
}
else {
logWarn("Purchase signature verification **FAILED**. Not adding item.");
logDebug(" Purchase data: " + purchaseData);
logDebug(" Signature: " + signature);
verificationFailed = true;
}
}

此方法“queryInventoryAsync”来自 IabHelper.java 类并返回库存信息:

public void queryInventoryAsync(final boolean querySkuDetails,
final List<String> moreSkus,
final QueryInventoryFinishedListener listener) {
final Handler handler = new Handler();
checkNotDisposed();
checkSetupDone("queryInventory");
flagStartAsync("refresh inventory");
(new Thread(new Runnable() {
public void run() {
IabResult result = new IabResult(BILLING_RESPONSE_RESULT_OK, "Inventory refresh successful.");
Inventory inv = null;
try {
inv = queryInventory(querySkuDetails, moreSkus);
}
catch (IabException ex) {
result = ex.getResult();
}

flagEndAsync();

final IabResult result_f = result;
final Inventory inv_f = inv;
if (!mDisposed && listener != null) {
handler.post(new Runnable() {
public void run() {
listener.onQueryInventoryFinished(result_f, inv_f);
logDebug("Result: "+ result_f.getResponse() + " inventory: "+ inv_f.getAllOwnedSkus().get(0));
}
});
}
}
})).start();
}

这是来 self 的 PurchaseActivity:

IabHelper.QueryInventoryFinishedListener mInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {

// Is it a failure?
if (result.isFailure()) {
Log.i(TAG, "Failed to query inventory: " + result);
return;
}else{
//This returns false
Log.i(TAG, "Query inventory was successful: " + inventory.hasPurchase(sku));
}

// Do we have the premium upgrade?
//This returns null
Purchase premiumPurchase = inventory.getPurchase(sku);

尽管 queryPurchases 和 queryInventoryAsync 显示我的设备和电子邮件帐户存在购买,但 getPurchase(sku) 将 Purchase 显示为 null,而 hasPurchase(sku) 返回 false。

有人知道为什么会这样吗?谢谢!

最佳答案

我遇到了同样的问题,并通过这种方式解决了

  • 将应用草稿上传为带有一些版本代码的 alpha 或 beta。
  • 使用有效订阅的帐户登录设备。
  • 在此设备上安装与 alpha/beta 版本相同的已签名应用程序。

关于安卓应用内订阅 : Inventory call returns purchase as null even if purchase exists,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22204093/

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