简体   繁体   中英

Admob Adview Banner Ad show in Android apps

In my Activity I have used this

public class MainActivity extends Activity {

AdView adView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    adView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().addTestDevice(
            "BD9386F17F7DE795B86B5BBBEDDF1095").build();
    adView.loadAd(adRequest);
}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    adView.pause();
}

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    adView.resume();
}

@Override
protected void onDestroy() {
    // TODO Auto-generated method stub
    super.onDestroy();
    adView.destroy();
}

}

in my xml i used this

  <com.google.android.gms.ads.AdView
     xmlns:ads="http://schemas.android.com/apk/res-auto"
     android:id="@+id/adView"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentBottom="true"
     ads:adSize="SMART_BANNER"
     ads:adUnitId="ca-app-pub-5000769796423780/7961881354" />

And in My Manifest

I have used this permission

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

And This metadata

<meta-data android:name="com.google.android.gms.version"
                android:value="@integer/google_play_services_version"/>

I have used this code all the time but this time it is not working. Even there is no error in Logcat. Recently i used api-21.

Have you added the AdActivity to the manifest ?

<activity 
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM