Reputation: 135
i was trying to set admob ads in my app with the new google-service-libs. and everything looks fine in genymotion emulator ads are showing up. but they don't at real device like my galaxy ace gt5830i with android 2.3.6. and i dont know what is the problem.
here is some code:
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/titleBar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/title_bar"
android:orientation="horizontal" >
<ImageView
android:id="@+id/iconImg"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_margin="5dip"
android:background="@drawable/app_icon" />
<ImageView
android:id="@+id/titleImg"
android:layout_width="160dp"
android:layout_height="45dp"
android:layout_gravity="center"
android:layout_margin="5dip"
android:background="@drawable/title" />
<RelativeLayout
android:id="@+id/pagerBtn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingRight="2dip" >
<ImageButton
android:id="@+id/pager"
android:layout_width="45dp"
android:layout_height="35dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@drawable/button_clicked"
android:scaleType="fitXY"
android:src="@drawable/pager" />
</RelativeLayout>
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="5dip"
android:background="@drawable/shadow" >
</View>
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
ads:adSize="BANNER"
ads:adUnitId="@string/adUnitId" />
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/buttons"
android:divider="#351802"
android:dividerHeight="2dp"
android:listSelector="@drawable/list_selector" />
</LinearLayout>
my Ad_Unit_Id is saved in string.xml file in res/ folder.
java :
AdView ad = (AdView) findViewById(R.id.adView);
AdRequest req = new AdRequest.Builder().build();
ad.loadAd(req);
Please tell me if you need more code. Thanks
Upvotes: 0
Views: 972
Reputation: 345
I've faced this problem before, it's because the ads banner needs a resolution that's bigger than the mobile's resolution.
For this reason test the application horizontally and once you do you'll be able to see the ads in full.
Upvotes: 1
Reputation: 7927
Try defining the ad's adsize
dynamically based on the devices' screen resolutions:
AdSize adSize = AdSize.SMART_BANNER;
DisplayMetrics dm = getResources().getDisplayMetrics();
double density = dm.density * 160;
double x = Math.pow(dm.widthPixels / density, 2);
double y = Math.pow(dm.heightPixels / density, 2);
double screenInches = Math.sqrt(x + y);
if (screenInches > 8) { // > 728 X 90
adSize = AdSize.LEADERBOARD;
} else if (screenInches > 6) { // > 468 X 60
adSize = AdSize.MEDIUM_RECTANGLE;
} else { // > 320 X 50
adSize = AdSize.BANNER;
}
ad = (AdView) findViewById(R.id.adView);
adView.setAdSize(adSize);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
Upvotes: 0