0

有没有关于如何使用 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();
}

我在谷歌和文档中没有找到任何示例,所以任何指导都会很棒。

4

1 回答 1

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());
于 2012-08-09T10:06:14.167 回答