How can i know whether I have adds to show, which I get from admob server?
I have a adView in my application UI i don't want to display it when there is no ads to display.
How can i know whether my application have ads to display?
this is my layout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/measurements.areaconvertor"
android:id="@+id/root_layout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.admob.android.ads.AdView
android:id="@+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
myapp:backgroundColor="#000000"
myapp:primaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC"/>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
开发者_开发技巧 .................
In my experience, an AdView automatically hides if no ads are present when you use wrap_content
for height.
<com.admob.android.ads.AdView
android:id="@+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
myapp:backgroundColor="#000000"
myapp:primaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC" />
i did it this way
if(!isOnline()){
LinearLayout li=(LinearLayout)findViewById(R.id.linearLayourID);
AdView ad=(AdView)findViewById(R.id.adView);
ad.setEnabled(false);
li.setWeightSum(8);
}
public boolean isOnline() {
ConnectivityManager cm =
(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
return true;
}
return false;
}
精彩评论