android - Upgrading AdMob SDK and fail on load() method -
i've been working update new admob requires google services function. i'm using code in oncreate()
adview adview = (adview)this.findviewbyid(r.id.adview); //adrequest adrequest adrequest = new adrequest.builder().addtestdevice(adrequest.device_id_emulator).build(); adview.loadad(adrequest); log.d("admob", "successfully loaded");
and using code in xml
<com.google.android.gms.ads.adview xmlns:ads="http://schemas.android.com/apk/res-auto" android:id="@+id/adview" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_gravity="center_horizontal" ads:adsize="smart_banner" ads:adunitid="admob_id"/>
however, admob advertisement not display. try/catch block fails here:
adview.loadad(adrequest);
the androidmanifest code looks this:
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> <activity android:name="com.google.android.gms.ads.adactivity" android:configchanges="keyboard|keyboardhidden|orientation|screenlayout|uimode|screensize|smallestscreensize" />
what missing?
referring admob android guides quote
next, create onactivitycreated method. you'll build , load adrequest. reference adview, build , load adrequest.
so, must implement next :
@override public void onactivitycreated(bundle bundle) { super.onactivitycreated(bundle); adview madview = (adview) getview().findviewbyid(r.id.adview); adrequest adrequest = new adrequest.builder().build(); madview.loadad(adrequest); }
android admob
No comments:
Post a Comment