我对 Android 应用内计费的恢复交易感到非常困惑。
我有这个片段用于在我的应用程序中进行捐赠:
BillingHelper.requestPurchase(mContext, "donation");
它工作得很好,没有任何问题。问题就在这里,当购买完成时我设置了一个布尔值:
if (BillingHelper.latestPurchase.isPurchased()) {
DONATE_VERSION = true;
}
此后应用程序将按预期运行,除非用户卸载该应用程序。我将 DONATE_VERSION 存储在共享首选项中。将购买信息存储在互联网上的个人数据库中不是一种选择。
当用户重新安装应用程序时,他们可以从捐赠中删除广告的唯一方法就是再次捐赠!我不希望出现这样的情况。我希望能够向 Google 查询已购买哪些物品(在本例中为“捐赠”物品)的结果。我在 onCreate() 中调用它:
BillingHelper.restoreTransactionInformation(BillingSecurity.generateNonce());
但现在怎么办?如果用户之前购买了“捐赠”的应用程序内购买管理,我如何查询谷歌以获取有关从应用程序内结算中购买了哪些项目的信息,以便我可以再次设置我的布尔值?请尽可能清楚地说明这一点,因为我一直在处理这个问题,在 IRC 上聊天,并搜索 API 大约 6 个小时,但我无法弄清楚这一点。
EDIT:
我的 onReceive() 方法:
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.i(TAG, "Received action: " + action);
if (ACTION_PURCHASE_STATE_CHANGED.equals(action)) {
String signedData = intent.getStringExtra(INAPP_SIGNED_DATA);
String signature = intent.getStringExtra(INAPP_SIGNATURE);
purchaseStateChanged(context, signedData, signature);
} else if (ACTION_NOTIFY.equals(action)) {
String notifyId = intent.getStringExtra(NOTIFICATION_ID);
notify(context, notifyId);
} else if (ACTION_RESPONSE_CODE.equals(action)) {
long requestId = intent.getLongExtra(INAPP_REQUEST_ID, -1);
int responseCodeIndex = intent.getIntExtra(INAPP_RESPONSE_CODE, C.ResponseCode.RESULT_ERROR.ordinal());
checkResponseCode(context, requestId, responseCodeIndex);
} else {
Log.e(TAG, "unexpected action: " + action);
}