我想在我的測試應用程序中集成admob代碼,這裏是我遵循的步驟。如何將adwhirl代碼集成到android應用程序
佈局文件看起來像這樣
<?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);
}
}
如果我這樣做,我的應用程序崩潰,並沒有廣告出現。請幫助我解決問題。
如果我錯了,請原諒我的無知,但我沒有理由將其標記爲C++。 – Drise 2012-07-24 15:25:35