I tried to integrate the admob banner in my application for several hours, but I could not do this, so I created a new application whose sole purpose is to show the admob banner, but it does not work either. here is the code
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); AdView adView = new AdView(this, AdSize.BANNER, "XXX"); adView.setVisibility(View.VISIBLE); RelativeLayout layout = new RelativeLayout(this); RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); adParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); layout.addView(adView, adParams); setContentView(layout); AdRequest adRequest = new AdRequest(); adView.loadAd(adRequest); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } }
and here is my manifest file
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.zzzzzz_admobtest" android:versionCode="1" android:versionName="1.0" > <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.zzzzzz_admobtest.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" /> </application> </manifest>
what am I doing wrong?
Also, when I output adView.isActivated () and adView.isReady (), both of them are false.
I use "XXX" instead of ID because I don't have one. Could this be a problem?
I am using a device. Here are the errors on ligcat
08-07 22: 43: 04.248: E / ActivityThread (24181): Failed to find provider information for com.google.plus.platform 08-07 22: 43: 04.454: E / Ads (24181): JS: Uncaught ReferenceError : AFMA_getSdkConstants not defined ( http://media.admob.com/:1 ) 08-07 22: 43: 04.454: E / Web Console (24181): Uncaught ReferenceError: AFMA_getSdkConstants not defined in http: //media.admob. com /: 1
last 2 errors can be fixed with this code
(new Thread() { public void run() { Looper.prepare(); adView.loadAd(new AdRequest()); } }).start();
as I understand it, the first of them is not a mistake, but just a warning. so why doesn't it work?