I am using Admob SMART_BANNER in my android app. The app is showing when device is in portrait mode. But if the device orientation is in landscape mode then the add is not showing. I know banner add is not shown if there is not enough space to display an add. But in my case it seems to have enough space to display an add. Here is my code:
activity_main.xml file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="15dp"/>
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
strings.xml file in values folder:
<resources>
<string name="app_name">Banner Example</string>
<string name="banner_ad_unit_id">ca-app-pub-3940256099942544/6300978111</string>
</resources>
Java code:
TelephonyManager tManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
String uid = tManager.getDeviceId();
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder`enter code here`()
.addTestDevice(uid)
.build();
mAdView.loadAd(adRequest);
You can dynamically load adsize based on the devices' screen resolutions: