Yabor Habarov February 2016

How can I implement restore purchase in android

Thanks for visiting my page.

Few days ago, I've developed simple android game with in app-billing.

Now I am going to implement restore purchase function but I don't know how can I dot it.

I've made few days of googling and found many links to help it but they didn't work me now.

Please let me know how to do it programmatically.

Where can i find sample of restore purchase ?

I've implement in app purchase already but not restore purchase.

I used Android Studio 1.5.1.

I've refered http://www.techotopia.com/index.php/An_Android_Studio_Google_Play_In-app_Billing_Tutorial to implement in app purchase.

Please help me :(

Thanks for advance.

Answers


Nithinjith February 2016

If you are implemented the InApp Purchase using v3 you need not worry about the restore Purchase implementation. You can query the inventory and catch the existing Purchase information. Please check the implementation.

What I did here is I have already a purchase module. While I complete the purchase, I will send the information to our server. After relog in or come back to the application, the server will send the current user purchase info whether he is Purchased or not. if the server gives a negative result, I will check the query inventory that is there any existing purchase over there. For that, I am using the following code in the MainActivity onCreate().

 mHelper = new IabHelper(this, base64EncodedPublicKey);
        mHelper.enableDebugLogging(true);
        Log.d(TAG, "Starting setup.");
        mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
            public void onIabSetupFinished(IabResult result) {
                Log.d(TAG, "Setup finished.");
                if (!result.isSuccess()) {
                    Log.e(TAG, "In App Set UP error:: Please check gmail account settings/ Credit Card Info etc");
                    return;
                }
                if (mHelper == null) return;
                mBroadcastReceiver = new IabBroadcastReceiver(MainActivity.this);
                IntentFilter broadcastFilter = new IntentFilter(IabBroadcastReceiver.ACTION);

                registerReceiver(mBroadcastReceiver, broadcastFilter);

                Log.d(TAG, "Setup successful. Querying inventory.");
                if (mSupplier.getmSubscriptionStatus() == 0) { // This is the Status given from Local Server 0- UnScubscribed User, 1- Subscribed User
                    mHelper.queryInventoryAsync(mGotInventoryListenerForPurchase);
                }
            }
        });

In the Result, You can Identify the existing purchase information.

I

abHelper.QueryInventoryFin 

Post Status

Asked in February 2016
Viewed 2,246 times
Voted 4
Answered 1 times

Search




Leave an answer