41

I have implemented ads in one of my apps and I want to make a in-app purchase feature to remove them. How would I do this.

I was thinking a simple way, was to hide the ads by making in invisible, after purchase. Could that work or is there an easier/better way?

I have no idea how to use the in-app feature for any purpose. Could anyone show me the way to code or something to read on this?

jcw
  • 5,132
  • 7
  • 45
  • 54
MoschDev
  • 671
  • 2
  • 14
  • 16
  • Possible duplicate of [Correctly disable AdMob ads](http://stackoverflow.com/questions/4549401/correctly-disable-admob-ads) – Sandy Chapman Mar 20 '16 at 18:58

2 Answers2

41

It depends on how you inserted the ads in the first place. If you did it via code, then just put an if(removed ads == false) around the code that inserts ads.

If you did it via XML, then the best way to do it is to copy out your XML, without the adview, and in your code use if surrounding all of your setContentView(R.layout.example)

Here's an example of what I mean

if (adsDisabled == true){
    setContentView(R.layout.mainNoAds)
} else{
    setContentView(R.layout.main
}

In-app purchases -

http://developer.android.com/guide/google/play/billing/billing_overview.html

In this post I assumed you are using admob, but the same should be true for all companies

On last thing - using adView.View.GONE IS bad practice **DO NOT ** do that

Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
jcw
  • 5,132
  • 7
  • 45
  • 54
  • ok, is making the adView GONE bad because the phones still running unused code everytime the app runs? Also i made this via code – MoschDev Nov 10 '12 at 15:22
  • Yes it is bad because they are still recording in your results, ie. they are still sending requests for ads - I believe, I am not sure about this because I cannot find the post where I originally saw this – jcw Nov 10 '12 at 15:24
  • @jcw Rational explanation for your statement about View.GONE with reference please. I know of absolutely no reason. Ah, hang on, I see, you don't mean in general, you mean specifically for not showing ads. – Simon Nov 10 '12 at 15:24
  • Yes, though I am still not sure about that, if someone disproves it then they are free to remove that – jcw Nov 10 '12 at 15:28
  • 3
    No, you're right since View.GONE "uses no space for layout purposes" but the instance of the view is still created. It effectively reports that it wants 0 height and 0 width to it's parent view. I stupidly downvoted because I read it as a generic statement but have cancelled that and added an upvote by way of atonement :) – Simon Nov 10 '12 at 15:39
  • Is there anyway to take effect immediately after the purchase? this way need to restart the app. – zdd Oct 26 '15 at 12:48
  • We should make adsDisabled a sharedPreference right? – Ruchir Baronia Nov 14 '15 at 21:32
3

I haven't tested this, yet.

It looks like you can also completely remove the view:

Correctly disable AdMob ads

Community
  • 1
  • 1
jnrcorp
  • 1,905
  • 1
  • 18
  • 25