Android的应用内结算RESTORE_TRANSACTION使用 [英] Android In-app billing RESTORE_TRANSACTION usage
本文介绍了Android的应用内结算RESTORE_TRANSACTION使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有可用的例子如何使用RESTORE_TRANSACTIONS请求恢复应用内购买产品的信息?我想出了这个code,但它始终返回0,因此,如果产品被购买或没有也承认:一切都设置正确
Is there any example available on how to use RESTORE_TRANSACTIONS request to restore an In-app product purchase information? I came up with this code, but it always returns 0, so it doesn't recognize if the product is purchased or not: Everything is set up correctly.
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();
}
我发现谷歌和文档中没有例子,所以任何指导将是巨大的。
I found no examples on google and in the documentation, so any guidance would be great.
推荐答案
我用这个方法:
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());
这篇关于Android的应用内结算RESTORE_TRANSACTION使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文