我想在我的测试应用程序中集成 admob 代码,这是我遵循的步骤。
布局文件看起来像这样
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom"
android:id="@+id/layout_ad">
</LinearLayout>
清单文件看起来像这样
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".Dummyads2Activity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
最后是代码的外观
public class Dummyads2Activity extends Activity {//implements AdWhirlInterface{
/** Called when the activity is first created. */
private AdWhirlLayout adWhirlLayout;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try{
AdManager.setTestDevices( new String[] { AdManager.TEST_EMULATOR } );
LinearLayout layout = (LinearLayout)findViewById(R.id.layout_ad);
AdWhirlLayout adWhirlLayout = new AdWhirlLayout(this, "my adwhirl id");
Display d = this.getWindowManager().getDefaultDisplay();
RelativeLayout.LayoutParams adWhirlLayoutParams = new RelativeLayout.LayoutParams(d.getWidth(), 72);
layout.addView(adWhirlLayout, adWhirlLayoutParams);
}catch(Exception e){
//Log.e(TAG, "Unable to create AdWhirlLayout", e);
}
}
如果我这样做,我的应用程序会崩溃,并且不会出现广告。请帮助我解决问题。