RealBercik
RealBercik

Reputation: 139

How to use in-app billing to permanently hide adds ??? Android

I've just implemented ads into my app, and I want to add an option for user to permanently hide ads using in app billing ...

How do I do it?

Thanks in advance :D

PS I have implemented ads using an xml file

Upvotes: 0

Views: 1332

Answers (2)

Ivan
Ivan

Reputation: 4234

I think that you can use sharedPreferences to store the status of the application.

If the user purchase purchase the adfree option you change the status of one item of the sharedPreference.

Just for example after the purchase you must do something like that:

SharedPreferences preferences = 
PreferenceManager.getDefaultSharedPreferences(this);
// The SharedPreferences editor - must use commit() to submit changes
SharedPreferences.Editor editor = preferences.edit();

// Edit the saved preferences
editor.putString("status", "purchased");
editor.commit();

And then when the application starts you must check that preference value and request ads only if the user hasn't the status purchased. For example:

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.getString("status", "free");

if(prefs.equals("free") {
        AdView adView = (AdView) findViewById(R.id.adViewMain);                
        adView.loadAd(new AdRequest());   
}

The problem is when the user uninstall the application, in that case the problem is that if the user has already purchased the adfree option, he must continue to work without ads. In that case the In-App Billing helps you, if you set the purchase item as a managed, in that case google market stores permanently the informations about the transaction, and when the application start the firstTime, using in-app billing, you can check all the previous transactions using the RESTORE_TRANSACTION option.

Check here for explanation of differences between managed and unmanaged apps: http://developer.android.com/guide/market/billing/billing_admin.html#billing-purchase-type Hope that help.

Upvotes: 3

Blundell
Blundell

Reputation: 76574

  1. Give each of your adverts an id in your XML layout

  2. Implement InApp billing

  3. check for successful purchase

  4. reference the id using the findViewById(int id) method

  5. set the visibility advert.setVisibility(View.GONE);

If your needing it as a permanent setting, store the fact they have purchased the item and do the check in onCreate calling setVisibility as above

Upvotes: 0

Related Questions