Android In-app billing RESTORE_TRANSACTION usage

帅比萌擦擦* 提交于 2019-12-13 07:01:02

问题


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.


回答1:


I used this method:

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());
        }
    }

, The call is as follows:

BillingHelper.restoreTransactionInformation(BillingSecurity.generateNonce());


来源:https://stackoverflow.com/questions/11563796/android-in-app-billing-restore-transaction-usage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!