我想检查android inapp帐单是否已购买。我发现这种方法...

protected static void verifyPurchase(String signedData, String signature) {
    ArrayList<VerifiedPurchase> purchases = BillingSecurity.verifyPurchase(signedData, signature);
    Log.e("IN APP","purchases: " + purchases.toString());
}


但是我不知道该把我放在signedData和签名中吗?尝试itemid和base64EncodedPublicKey,不起作用...

谢谢!

最佳答案

要检查购买结果,您应该使用BillingPurchaseObserver类的另一种方法:

@Override
public void onRequestPurchaseResponse(RequestPurchase request,
        ResponseCode responseCode)
{
    Log.d("TAG", "onRequestPurchaseResponse");
    if (Consts.DEBUG)
    {
        Log.d("TAG", request.mProductId + ": " + responseCode);
    }
    if (responseCode == ResponseCode.RESULT_OK)
    {
        if (Consts.DEBUG)
        {
            Log.i("TAG", "purchase was successfully sent to server");
        }
    }
    else if (responseCode == ResponseCode.RESULT_USER_CANCELED)
    {
        if (Consts.DEBUG)
        {
            Log.i("TAG", "user canceled purchase");
        }
    }
    else
    {
        if (Consts.DEBUG)
        {
            Log.i("TAG", "purchase failed");
        }
    }
}


还有BillingService中的PurchaseStateChanged方法,您不应该修改。

/**
     * Verifies that the data was signed with the given signature, and calls
     * {@link ResponseHandler#purchaseResponse(Context, PurchaseState, String, String, long)}
     * for each verified purchase.
     *
     * @param startId
     *           an identifier for the invocation instance of this service
     * @param signedData
     *           the signed JSON string (signed, not encrypted)
     * @param signature
     *           the signature for the data, signed with the private key
     */
    private void purchaseStateChanged(int startId, String signedData,
            String signature)
    {
            //...
    }

10-04 16:55