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

  • Home
  • SEARCH
  • 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 9130543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:58:58+00:00 2026-06-17T07:58:58+00:00

I implemented Google in App. its working fine after publishing the app. but i

  • 0

I implemented Google in App. its working fine after publishing the app. but i am facing a problem . When user install the app and then purchase the items and then uninstall the app and reinstall it and goes to the purchased items then app agian lock the purchsed item and ask for purchase request. is there any problem in OnRestoreTransaction?
I used code from the Google In app Purchse site.
Here is the code :

 private class DungeonsPurchaseObserver extends PurchaseObserver {
        public DungeonsPurchaseObserver(Handler handler) {
            super(in_app.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 (purchaseState == PurchaseState.PURCHASED ) {
                finish();
            }
        }


        @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");
                }
            } 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");
                }
            }
        }

        @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 = getPreferences(Context.MODE_PRIVATE);
                SharedPreferences.Editor edit = prefs.edit();
                edit.putBoolean(DB_INITIALIZED, true);
                edit.commit();
            } else {
                if (Consts.DEBUG) {
                    Log.d(TAG, "RestoreTransactions error: " + responseCode);
                }
            }
        }
    }


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.in_app);

        mHandler = new Handler();
        mDungeonsPurchaseObserver = new DungeonsPurchaseObserver(mHandler);
        mBillingService = new BillingService();
        mBillingService.setContext(this);

        mPurchaseDatabase = new PurchaseDatabase(this);
        //setupWidgets();

        // Check if billing is supported.
        ResponseHandler.register(mDungeonsPurchaseObserver);
        if (!mBillingService.checkBillingSupported()) {
            showDialog(DIALOG_CANNOT_CONNECT_ID);
        }



        purchase=(Button) findViewById(R.id.purchase);
        cancel=(Button) findViewById(R.id.cancel);

        purchase.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                if(!ownedItems.contains("android.test.refunded")){      
                    if (Consts.DEBUG) {
                        Log.d(TAG, "buying: " + "  product" + " Product Name: " + "Product");
                    }

                    if (!mBillingService.requestPurchase("android.test.refunded", mPayloadContents)) {
                        showDialog(DIALOG_BILLING_NOT_SUPPORTED_ID);
                    }
            }
            }
        });

Edited:

I call this in onCrearte of in-app java file :
this first checks that whehter the current user purchased the item for which he is demanding and if not then iniate request for Purchase.
In onPurchsestateChanged i only checked that state is Purchased or not.

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.in_app);

    mHandler = new Handler();
    mDungeonsPurchaseObserver = new DungeonsPurchaseObserver(mHandler);
    mBillingService = new BillingService();
    mBillingService.setContext(this);

    mPurchaseDatabase = new PurchaseDatabase(this);
    //setupWidgets();

    // Check if billing is supported.
    ResponseHandler.register(mDungeonsPurchaseObserver);
    if (!mBillingService.checkBillingSupported()) {
        showDialog(DIALOG_CANNOT_CONNECT_ID);
    }
    System.out.println("for check"+getPreferences(Context.MODE_PRIVATE).getBoolean(DB_INITIALIZED, false));

    if (getPreferences(Context.MODE_PRIVATE).getBoolean(DB_INITIALIZED, false)) {
        System.out.println(mBillingService.restoreTransactions());
    }
    else{
    purchase=(Button) findViewById(R.id.purchase);
    cancel=(Button) findViewById(R.id.cancel);

    purchase.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            if(!ownedItems.contains("android.test.refunded")){      
                if (Consts.DEBUG) {
                    Log.d(TAG, "buying: " + " product" + " Product Name: " + "i");
                }


                if (!mBillingService.requestPurchase("android.test.refunded", mPayloadContents)) {
                    showDialog(DIALOG_BILLING_NOT_SUPPORTED_ID);
                }
        }
        }
    });


    cancel.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            finish();
            startActivity(new Intent(in_app.this, Main.class));
            overridePendingTransition(R.anim.slide_in_right,R.anim.slide_out_right);
        }
    });
    }
}

OnPurchaseStateChanged:

    public void onPurchaseStateChange(PurchaseState purchaseState, String itemId,
            int quantity, long purchaseTime, String developerPayload) {

        if (Consts.DEBUG) {
            Log.i(TAG, "onPurchaseStateChange() itemId: " + itemId + " " + purchaseState);
        }
        System.out.println("here for new fun");
        if (purchaseState == PurchaseState.PURCHASED ) {

            finish();
            Intent intent1 = new Intent(context,BodyParts1.class);
            context.startActivity(intent1);
        }


    }
  • 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-17T07:58:59+00:00Added an answer on June 17, 2026 at 7:58 am

    In order to restore all purchased items you have to explicitly call mBillingService.restoreTransactions(). Then you will receive onPurchaseStateChange callback for each previously purchased item.

    Put this code in onCreate method and it should work well:

    if (!getPreferences(Context.MODE_PRIVATE).getBoolean(DB_INITIALIZED, false)) {
        mBillingService.restoreTransactions();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have implemented google play successfuly....and its working fine.....but when i close my application
I have implemented the in-app billing based on the dungeons google code, but I
I started with python on google app engine 3 months ago. Then I switched
Apple states in its App Store Review Guidelines Apps using IAP to purchase physical
I'm trying to implement the use of Google Drive in my app but I
I have to profile my multithreaded C++ app and find its bottlenecks. The problem
Trying to implement google C2DM service. registrationIntent.putExtra(app, PendingIntent.getBroadcast(context,0,new Intent(), 0)); registrationIntent.putExtra(sender,example@gmail.com); context.startService(registrationIntent); Almost every
I am trying to fetch URLs using Google App Engine's urlFetch service and implement
I am trying to use django-social-auth to implement google openid login into my app,
I have implemented Google Analytics in my iPhone Application. And I can able to

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.