0

我想在我的测试应用程序中集成 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);
    }

}

如果我这样做,我的应用程序会崩溃,并且不会出现广告。请帮助我解决问题。

4

1 回答 1

0

这实际上取决于您使用的 AdMob 和 AdWhirl 版本。我将讨论 AdMob SDK v6.1.0 和 AdWhirl v3.2.0,它们是目前最新的版本。

你可能因为这条线而崩溃:

AdManager.setTestDevices( new String[] { AdManager.TEST_EMULATOR } );

这看起来像旧版 AdMob AdManager;AdWhirl 使用 Google AdMob SDK。无论如何,如果您想使用 AdWhirl 测试广告,您需要通过 AdWhirl 设置测试,而不是通过广告网络。所以删除上面的行并像这样设置测试模式:

AdWhirlTargeting.setTestMode(true);

此外,您的清单将需要具有您正在调解的网络的所有权限和活动定义的超集。对于 AdMob,您需要添加:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
...
<activity android:name="com.google.ads.AdActivity"
              android:configChanges="orientation|keyboard|keyboardHidden|screenLayout|uiMode|screenSize|smallestScreenSize" />

如果您仍然遇到错误,发布一些日志输出会很有用。如果您使用的是 Eclipse,您可以从 Window -> Show View -> Other... -> Android -> LogCat 找到 logcat。adb logcat或者,您可以使用Android 的 adb 工具从命令行获取 logcat 输出。

于 2012-07-24T21:30:11.483 回答