Game Development Reference
In-Depth Information
< activity android:name = "com.google.android.gms.ads.AdActivity"
android:configChanges = "keyboard|keyboardHidden|orientation" />
</ application >
< uses-sdk
android:minSdkVersion = "7"
/>
< uses-permission android:name = "android.permission.INTERNET" />
< uses-permission
android:name = "an-
droid.permission.ACCESS_NETWORK_STATE" />
</ manifest >
Step 6: Adding showAds() method
Before adding showAds() method, you should import the Google Mobile Ads package
com.google.android.gms.ads in the main activity:
import com.google.android.gms.ads.*;
Then, declare a few variables as below. AdView is a view that will hold the Admob html5
ads, replace <YOUR_AD_UNIT_ID> with your admob unit ID.
AdView av;
LinearLayout layout;
RelativeLayout.LayoutParams adParams;
String MY_AD_UNIT_ID = "<YOUR_AD_UNIT_ID>" ;
Here is the implementation snippet:
public void showAds(){
try {
layout = new LinearLayout( this );
addContentView(layout,
new
Layout-
Params(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
//creates the adView to load admob html5 ads
av = new AdView( this , AdSize.BANNER, MY_AD_UNIT_ID);
Search WWH ::




Custom Search