我正在基于LibGDX的Android应用中设置来自Google Play的Inn-App结算。
情景:我已经购买了测试产品" android.test.purchased "成功了,我没有消耗它。我没有消耗它,因为它只能购买一次而且我已禁用该测试产品的购买按钮。直到这一切都很好。
问题:现在我再次打开第二次。我收到一条警告说"无法查询库存:IabResult:刷新库存时出错(查询自有物品)。 (回复:-1003:购买签名验证失败"。
问题: 我希望我的产品只能购买一次,因此我没有消费它。在onCreate()中查询库存时会出现问题。
mHelper.queryInventoryAsync(mGotInventoryListener);
private void iabSetup() {
// load game data
loadData();
String base64EncodedPublicKey = "Key";
Log.d(TAG, "Creating IAB helper.");
mHelper = new IabHelper(this, base64EncodedPublicKey);
mHelper.enableDebugLogging(true);
Log.d(TAG, "Starting setup.");
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
Log.d(TAG, "Setup finished.");
if (!result.isSuccess()) {
complain("Problem setting up in-app billing: " + result);
return;
}
if (mHelper == null) return;
Log.d(TAG, "Setup successful. Querying inventory.");
mHelper.queryInventoryAsync(mGotInventoryListener);
}
});
}
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
Log.d(TAG, "Query inventory finished.");
// Have we been disposed of in the meantime? If so, quit.
if (mHelper == null) return;
// Is it a failure?
if (result.isFailure()) {
complain("Failed to query inventory: " + result);
return;
}
Log.d(TAG, "Query inventory was successful.");
// Do we have the additional 1 life?
Purchase life1Purchase = inventory.getPurchase(SKU_1_Life);
life1Purchased = (life1Purchase != null);
Log.d(TAG, "User life1Purchased : " + life1Purchased);
};
public void onAdd1lifeButtonClicked() {
if (!mHelper.subscriptionsSupported()) {
complain("Subscriptions not supported on your device yet. Sorry!");
return;
}
Log.d(TAG, "Launching purchase flow for infinite gas subscription.");
if (busy) {
Log.d(TAG, "Can't buy item. So busy yet");
return;
}
try {
new Thread(new Runnable() {
@Override
public void run() {
busy = true;
mHelper.launchPurchaseFlow(AndroidLauncher.this, SKU_1_Life, RC_REQUEST, mPurchaseFinishedListener, payloadString);
}
}).start();
} catch (Exception e) {
Log.d(TAG, "buyItem Exception: " + e);
}
}
// Callback for when a purchase is finished
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
Log.d(TAG, "Purchase finished: " + result + ", purchase: " + purchase);
// if we were disposed of in the meantime, quit.
if (mHelper == null) return;
if (result.isFailure()) {
complain("Error purchasing: " + result);
return;
}
if (!verifyDeveloperPayload(purchase)) {
complain("Error purchasing. Authenticity verification failed.");
return;
}
Log.d(TAG, "Purchase successful.");
if (purchase.getSku().equals(SKU_1_Life)) {
Log.d(TAG, "Purchase is SKU_1_Life.");
busy = false;
}
}
};