Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

android - admob : changing ads

I use following code to show ads in onCreate() of the activity Since my activity is displayed for longer times, can I refresh the ads ? or will it automatically refresh them ? Do I even need to change them or should not bother it ?

        //only ask for test ad, in emulator , should remove this later in real device
        AdRequest adRequest = new AdRequest();
        //adRequest.addTestDevice(AdRequest.TEST_EMULATOR);               // Emulator
        //adRequest.addTestDevice("TEST_DEVICE_ID");                

         // Create the adView
        adView = new AdView(this, AdSize.BANNER, "908908098098");

        // Lookup your LinearLayout assuming it’s been given
        // the attribute android:id="@+id/mainLayout"    

        LinearLayout layout = (LinearLayout)findViewById(R.id.adLayout);

        // Add the adView to it
        layout.addView(adView);

        // Initiate a generic request to load it with an ad
        adView.loadAd(adRequest);                   
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Change app settings in admob account:

enter image description here

Also you should remove test mode before publishing:

    AdView adView = (AdView) findViewById(R.id.ad);
    AdRequest adRequest = new AdRequest();
    adView.loadAd(adRequest);

In onDestroy(): adView.destroy();

In layout:

<com.google.ads.AdView
    android:id="@+id/ad"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    ads:adSize="BANNER"
    ads:adUnitId="@string/admob_publisher_id"
    ads:loadAdOnCreate="true" >
</com.google.ads.AdView>

In AdMob app settings select this: Disable test mode for all requests


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...