Billingservice Android - No signature
Asked Answered
M

1

5

I have followed to following great tutorial at : http://blog.blundell-apps.com/simple-inapp-billing-payment/

I have done everything the tutorial says and have read everything 3 times over again but still i am not receiving a signature in the intent.getStringExtra(INAPP_SIGNATURE) in onReceive() : BillingReceiver.java

which makes my app crash because the app cant compare signatures to verify if the purchase is done correctly.

This is how my BillingReceiver looks like:

public class BillingReceiver extends BroadcastReceiver {

    private static final String TAG = "BillingService";

    @Override
    public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            Log.i(TAG, "Received action: " + action);
    if (ACTION_PURCHASE_STATE_CHANGED.equals(action)) {
        String signedData = intent.getStringExtra(INAPP_SIGNED_DATA);
        String signature = intent.getStringExtra(INAPP_SIGNATURE);
        Log.e(TAG, "<!-- SIGNATURE : "+ intent.getExtras().getString("inapp_signature"));


        Log.i(TAG, "<!-- SIGNATURE : "+intent.getStringExtra(INAPP_SIGNATURE));

        purchaseStateChanged(context, signedData, signature);
    } else if (ACTION_NOTIFY.equals(action)) {
        String notifyId = intent.getStringExtra(NOTIFICATION_ID);
        notify(context, notifyId);
    } else if (ACTION_RESPONSE_CODE.equals(action)) {
        long requestId = intent.getLongExtra(INAPP_REQUEST_ID, -1);
        int responseCodeIndex = intent.getIntExtra(INAPP_RESPONSE_CODE, C.ResponseCode.RESULT_ERROR.ordinal());
        checkResponseCode(context, requestId, responseCodeIndex);
    } else {
       Log.e(TAG, "unexpected action: " + action);
    }
    }

    private void purchaseStateChanged(Context context, String signedData, String signature) {
            Log.i(TAG, "purchaseStateChanged got signedData: " + signedData);
            Log.i(TAG, "purchaseStateChanged got signature: " + signature);
            BillingHelper.verifyPurchase(signedData, signature);
    }

    private void notify(Context context, String notifyId) {
            Log.i(TAG, "notify got id: " + notifyId);
            String[] notifyIds = {notifyId};
            BillingHelper.getPurchaseInformation(notifyIds);
    }

    private void checkResponseCode(Context context, long requestId, int responseCodeIndex) {
            Log.i(TAG, "checkResponseCode got requestId: " + requestId);
            Log.i(TAG, "checkResponseCode got responseCode: " + C.ResponseCode.valueOf(responseCodeIndex));
    }
}
Machute answered 20/3, 2012 at 15:47 Comment(1)
I am facing same issue. Any help appreciated.Tortola
T
5

Is the primary account on your test device the same as your Google Play developer account?

If not you won't get signatures on the android.test.* static responses unless the app has been published on Play before.

See the table at http://developer.android.com/guide/market/billing/billing_testing.html#static-responses-table for the full set of conditions.

Tonjatonjes answered 25/5, 2012 at 12:51 Comment(4)
I don't think that table quite holds. I should have been on row 6 of that table (published app (albeit not published with billing), draft apk with billing uploaded, non dev account on device), but I was getting a null sig. Changed to a dev device and it all works. Perhaps the first column refers to a published version of the app that already contains billing.Boyse
@Boyse I tried using in app billing version 3 api. Tried with developer's phone to purchase reserved product id's(static). Purchase was successful but signature was empty. Any idea's?Kotta
@Kotta I don't think the static ids return signature anymore. See groups.google.com/d/topic/android-developers/PCbCJdOl480/…Wilda
@Wilda hmm.. I found it out the hard way.. The only way to get signature now is to do real purchase using test accounts.. Very very very poor from google. The entire In app billing testing system is crap.. yjo you might want to update the answer with this info..Kotta

© 2022 - 2024 — McMap. All rights reserved.