3

我有这样的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
     android:orientation="vertical"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:id="@+id/archiveLayout"
     android:background="#ECECFC"
     >
     <ListView  
         android:id="@android:id/list"
         android:layout_alignParentTop="true"
         android:layout_width="fill_parent" 
         android:layout_above="@+id/ad_layout"
         android:divider="@drawable/divider" 
         android:dividerHeight="1px"
         android:background="#ECECFC"
         android:layout_height="wrap_content" 
         />
      <TextView
      android:id="@+id/tvHaltestellen"
         android:layout_centerInParent="true"
        android:layout_width="wrap_content"
     android:layout_height="wrap_content" />
          <LinearLayout android:layout_width="wrap_content"
       android:id="@+id/ad_layout" android:layout_height="wrap_content"
        android:gravity="bottom"
        android:layout_alignParentBottom="true"> 
        <com.google.ads.AdView android:id="@+id/adView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
             android:layout_alignParentBottom="true"
            android:gravity="center"
            ads:adUnitId="a15175676fe1308"
            ads:adSize="SMART_BANNER"
            /> 

           </LinearLayout> 

 </RelativeLayout>

这就是我下载广告的方式:

if (isOnline())
    {
        adView.loadAd(new AdRequest());
    }
    else
    {
        adView.setVisibility(View.GONE);
    }

isOnLine 方法检查互联网连接:

public boolean isOnline() {
   boolean res = false;
    ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (netInfo != null && netInfo.isConnectedOrConnecting()) {
       res= true;
    }
    else
    {
       res = false;
     }
    return res;
}

我试图从这个答案中获得帮助并在另一个线程中下载广告,但这对我没有帮助。

当我使用广告打开我的活动时,它有时不会打开,我得到下一个例外:

    10-01 12:24:43.423: E/Ads(26065): JS: Uncaught ReferenceError: AFMA_getSdkConstants is not defined (http://media.admob.com/:1)
10-01 12:24:43.423: E/Web Console(26065): Uncaught ReferenceError: AFMA_getSdkConstants is not defined at http://media.admob.com/:1
4

0 回答 0