是否有关于如何使用RESTORE_TRANSACTIONS请求恢复应用内商品购买信息的示例?我想出了这个代码,但它总是返回0,所以无法识别是否购买了产品:一切都设置正确。
Bundle request = BillingHelper.makeRequestBundle("RESTORE_TRANSACTIONS");
request.putLong("NONCE", 32436756l);
try
{
Bundle response = BillingHelper.mService.sendBillingRequest(request);
int response_code = response.getInt("RESPONSE_CODE", -1);
if (response_code == 0)
{
// Product purchased
}
}
catch (RemoteException e)
{
e.printStackTrace();
}
我在谷歌和文档中没有找到任何示例,因此任何指导都会很棒。
答案 0 :(得分:1)
我使用了这种方法:
public static void restoreTransactionInformation(Long nonce)
{
if (amIDead())
{
return;
}
Log.i(TAG, "confirmTransaction()");
Bundle request = makeRequestBundle("RESTORE_TRANSACTIONS");
// The REQUEST_NONCE key contains a cryptographically secure nonce (number used once) that you must generate
request.putLong("NONCE", nonce);
try
{
Bundle response = mService.sendBillingRequest(request);
//The REQUEST_ID key provides you with a unique request identifier for the request
Long requestIndentifier = (Long) response.get("REQUEST_ID");
Log.i(TAG, "current request is:" + requestIndentifier);
//The RESPONSE_CODE key provides you with the status of the request
Integer responseCodeIndex = (Integer) response.get("RESPONSE_CODE");
C.ResponseCode responseCode = C.ResponseCode.valueOf(responseCodeIndex);
Log.i(TAG, "RESTORE_TRANSACTIONS Sync Response code: "+responseCode.toString());
}
catch (RemoteException e)
{
Log.e(TAG, "Failed, internet error maybe", e);
Log.e(TAG, "Billing supported: " + isBillingSupported());
}
}
,电话如下:
BillingHelper.restoreTransactionInformation(BillingSecurity.generateNonce());