AdMob在Android版本2.3和4.2的模拟器上正确显示,但在真实设备(Android版本4.0.4)上没有显示。错误是
12-22 19:35:56.930: ERROR/Ads(6311): JS: Uncaught ReferenceError: AFMA_getSdkConstants is not defined (http://media.admob.com/:1)
12-22 19:35:56.930: ERROR/Web Console(6311): Uncaught ReferenceError: AFMA_getSdkConstants is not defined at http://media.admob.com/:1
代码是
admob_preference.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/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<com.google.ads.AdView
android:id="@+id/ad"
ads:adSize="BANNER"
android:layout_width="320dp"
android:layout_height="wrap_content"
ads:adUnitId="a150d2d17822fc0"
ads:loadAdOnCreate="true"/>
</LinearLayout>
AdmobPreference.java
public class AdmobPreference extends Preference
{
public AdmobPreference(Context context) {
super(context, null);
}
public AdmobPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected View onCreateView(ViewGroup parent) {
//override here to return the admob ad instead of a regular preference display
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
return inflater.inflate(R.layout.admob_preference, null);
}
}
的preferences.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<com.nbrk.rates.AdmobPreference android:key="ad" />
</PreferenceScreen>