I use cocos2d-x to write a simple game, i had build and published to Google Play, now i would like to integrated with admob.
I create main.xml file
`<?xml version="1.0" encoding="utf-8"?>
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
ads:adUnitId=“my admob publisher id”
ads:adSize=“BANNER”
ads:testDevices=“TEST_EMULATOR, TEST_DEVICE_ID”
ads:loadAdOnCreate=“true”/>
```
I add the AdActivity and permistion in my Manifest file
``````
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
And here is the code to load admob
`private AdView adView;
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//add admob advertise
try
{
setContentView(R.layout.main);
// Create the adView
adView = new AdView(this, AdSize.BANNER, "my admob publisher id");
adView.setGravity(Gravity.BOTTOM | Gravity.LEFT);
// Lookup your LinearLayout assuming it's been given
// the attribute android:id="@+id/mainLayout"
LinearLayout layout = (LinearLayout)findViewById(R.id.adView);
adView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
adView.setVisibility(AdView.VISIBLE);
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());
}
catch(Exception e)
{
Log.d("", "error: " + e);
}
}
@Override
protected void onDestroy() {
if (adView != null) {
adView.destroy();
}
super.onDestroy();
}`
I build and export successfully.
When i install to my test smart phone, when i run the game it show an empty screen, my game not run.
I don’t know why, when i test my smart phone don’t have internet.
Could you help me to solve this problem?