Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7915129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:21:20+00:00 2026-06-03T14:21:20+00:00

I am working on Google In-app purchase for an app. I have created a

  • 0

I am working on Google In-app purchase for an app. I have created a managed product item with id as “app.test.item”. I followed all other steps specified in the google documentation. For a first time purchase app is working fine. But when i try to unistall the app and install it again. The app runs a restore transaction request. The onRestoreTransactionsResponse() method gets called where i make the purchase status true based on the RESULT_OK returned from the Market. My doubt is how does the app know that only the item named “app.test.item” is purchased and is hence restored. I am having some other items too for example “app.test.second.item” . How does the in app billing see the difference between the two. I have used the Google provided in-app billing code. just mentioned few sharedpreferences to store the purchase status. Am i doing anything wrong here. Please guide me.

Also i want to test this app in debug mode so that i can trace out the workflow. But the apps should be signed with a release version. Is there any way i can run this app completely(to test the restore transactions) in debug version. I understood the general workflow for a general purchase using the reserved productId as “android.test.purchased”. But i need to test for restoreTransactions(). Any help is appreciated.

I am posting the PurchaseObserver sample code here.

Thanks,

private class DungeonsPurchaseObserver extends PurchaseObserver {
    public DungeonsPurchaseObserver(Handler handler) {
        super(Dungeons.this, handler);
    }

    @Override
    public void onBillingSupported(boolean supported) {
        if (Consts.DEBUG) {
            Log.i(TAG, "supported: " + supported);
        }
        if (supported) {
            restoreDatabase();
        } else {
            showDialog(DIALOG_BILLING_NOT_SUPPORTED_ID);
        }
    }

    @Override
    public void onPurchaseStateChange(PurchaseState purchaseState, String itemId,
            int quantity, long purchaseTime, String developerPayload) {
        if (Consts.DEBUG) {
            Log.i(TAG, "onPurchaseStateChange() itemId: " + itemId + " " + purchaseState);
        }

        if (developerPayload == null) {
            logProductActivity(itemId, purchaseState.toString());
        } else {
            logProductActivity(itemId, purchaseState + "\n\t" + developerPayload);
        }

        if (purchaseState == PurchaseState.PURCHASED) {
            mOwnedItems.add(itemId);
            logProductActivity("APPLICATION", ": STATE PURCHASED");
            SharedPreferences pref = getSharedPreferences(PREF_FILE, MODE_PRIVATE);
            SharedPreferences.Editor editor = pref.edit();
            editor.putString(PURCHASE_STATUS, "ITEM PURCHASED");
            editor.commit();
        }
        if(purchaseState == PurchaseState.CANCELED)
        {
            logProductActivity("APPLICATION", ": STATE CANCELLED");
            SharedPreferences pref = getSharedPreferences(PREF_FILE, MODE_PRIVATE);
            SharedPreferences.Editor editor = pref.edit();
            editor.putString(PURCHASE_STATUS, "ITEM CANCELLED");
            editor.commit();
        }
        if(purchaseState == PurchaseState.REFUNDED)
        {
            logProductActivity("APPLICATION", ": STATE REFUNDED");
            SharedPreferences pref = getSharedPreferences(PREF_FILE, MODE_PRIVATE);
            SharedPreferences.Editor editor = pref.edit();
            editor.putString(PURCHASE_STATUS, "ITEM REFUNDED");
            editor.commit();
        }
    }

    @Override
    public void onRequestPurchaseResponse(RequestPurchase request,
            ResponseCode responseCode) {
        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");
            }
            logProductActivity(request.mProductId, "sending purchase request");
        } else if (responseCode == ResponseCode.RESULT_USER_CANCELED) {
            if (Consts.DEBUG) {
                Log.i(TAG, "user canceled purchase");
            }
            logProductActivity(request.mProductId, "dismissed purchase dialog");
        } else {
            if (Consts.DEBUG) {
                Log.i(TAG, "purchase failed");
            }
            logProductActivity(request.mProductId, "request purchase returned " + responseCode);
        }
    }

    @Override
    public void onRestoreTransactionsResponse(RestoreTransactions request,
            ResponseCode responseCode) {
        if (responseCode == ResponseCode.RESULT_OK) {
            if (Consts.DEBUG) {
                Log.d(TAG, "completed RestoreTransactions request");
            }
            // Update the shared preferences so that we don't perform
            // a RestoreTransactions again.
            SharedPreferences prefs = getSharedPreferences(PREF_FILE, MODE_PRIVATE);
            SharedPreferences.Editor edit = prefs.edit();
            edit.putBoolean(DB_INITIALIZED, true);
            edit.putString(PURCHASE_STATUS, "ITEM PURCHASE RESTORED");
            edit.commit();
            logProductActivity("onRestoreTransactionsResponse() method in PurchaseObserver", "ITEM PURCHASE RESTORED");
        } else {
            if (Consts.DEBUG) {
                Log.d(TAG, "RestoreTransactions error: " + responseCode);
            }
        }
        logProductActivity("onRestoreTransactionsResponse() method in PurchaseObserver", responseCode.toString());
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T14:21:21+00:00Added an answer on June 3, 2026 at 2:21 pm

    Debugging managed products can be difficult as you cannot use them unless the app is signed with a release key. For this reason I sign my debug builds with my release key when testing IAB.

    Regarding multiple products, you need to check the item id. onPurchaseStateChange will be called for each product.

    e.g

    public void onPurchaseStateChange(PurchaseState purchaseState, String itemId, int quantity, long purchaseTime, String developerPayload) {
    
        if (itemId.equals("app.test.item") {
            switch (purchaseState) {
    
            case PURCHASED:
                Log.i("Billing","Purchased app.test.item");
                break;
    
            default:
                Log.i("Billing","Something else");
                break;
    
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get Django 1.1 working on Google App Engine. I followed
I am working on a Google app engine project where I have saved some
I am working on a Google App Engine application, and have been facing some
I'm working with Google App Engine and Facebook Connect. I have found Facebook Python
I'm working on an google app engine app that will have to deal with
I am working with Google App Engine and Python. I have a model with
I have a question regarding google app engine. Let us say you are working
I am new to google app engine and python. I have created an application
I'm working in the Google App Engine environment and programming in Python. I am
I'm working on a Google App Engine program that will require some basic spell

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.