Correctly disable AdMob ads

前端 未结 9 1639
感情败类
感情败类 2020-12-02 05:13

I am integrating AdMob into my app and I wonder how to disable Ads correctly. I want to give the user the ability to disable them. I don\'t want to get any problems with AdM

9条回答
  •  旧巷少年郎
    2020-12-02 05:54

    I also wanted to give users the ability to disable ads - why force people to see them if they don't want to? and why should you expect people to pay for that option?

    Anyway, I outlined how I did this in this article. The article goes into more detail but here's the relevant parts:

    The code i use to turn off ads:

    private void hideAd() {
        final AdView adLayout = (AdView) findViewById(R.id.adView1);
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                adLayout.setEnabled(false);
                adLayout.setVisibility(View.GONE);
            }
        });
    }
    

    And to turn them back on (in case anyone was feeling generous)

    private void showAd() {
        final AdView adLayout = (AdView) findViewById(R.id.adView1);
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                adLayout.setEnabled(true);
                adLayout.setVisibility(View.VISIBLE);
                adLayout.loadAd(new AdRequest());
            }
        });
    }
    

提交回复
热议问题