问题
I have an android app and I want add adMob ads. I have below codes, when I listen adView with onReceiveAd() the ads comes but not shows in layout Any idea?
adsLayout = (LinearLayout) findViewById(R.id.ads);
adView = new AdView(this, AdSize.SMART_BANNER, Constants.adMobId);
adsLayout.addView(adView);
adView.loadAd(new AdRequest().setTesting(true));
I have also internet permission and admob configchanges in manifest
adsLayout is
<LinearLayout
android:id="@+id/adsLayout"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:background="@android:color/white" >
</LinearLayout>
I pass publisherId with below code
adView = new AdView(this, AdSize.SMART_BANNER, Constants.adMobKey);
回答1:
Try this step:
Set Permission to manifest file:
<uses-permission android:name="android.permission.INTERNET" />
Put this code into onCreate Method:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Ad Code
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest();
adRequest.setTesting(true);
adView.loadAd(adRequest);
adView.loadAd(new AdRequest());
// End Ad Code
}
Before Publishing setTestDevice to test
AdManager.setTestDevices( new String[] {AdManager.TEST_EMULATOR});
AdView adView = (AdView)findViewById(R.id.adView);
adView.requestFreshAd();
Hope to help this
来源:https://stackoverflow.com/questions/17382419/admob-ads-not-showing-in-android-layout