Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k 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 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...