0

我有一个 Android 应用程序,我试图在其中显示广告。广告在运行 Android 4.1.2 的 Galaxy Nexus 上显示良好,但在运行 Android 2.3 的 Droid 2 上,它们不显示。

我找遍了整个地方,但我无法弄清楚我做错了什么

安卓清单:

<uses-sdk android:minSdkVersion="8"
        android:targetSdkVersion="16"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET" />
<application android:label="@string/app_name" android:icon="@drawable/sms_logo_green_w_blue">
    <activity android:name="com.google.ads.AdActivity"
              android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

XML 文件:

<com.google.ads.AdView
                android:id="@+id/adView"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                ads:adUnitId="@string/mediation_id"
                ads:adSize="BANNER"
                ads:testDevices="TEST_EMULATOR, <my device id>"
                ads:loadAdOnCreate="true"/>

我尝试通过 Java 代码而不是通过 XML 加载广告,如下所示:

com.google.ads.AdView adView = new com.google.ads.AdView(this, AdSize.BANNER, this.getResources().getString(R.string.mediation_id));
    LinearLayout layout = (LinearLayout)findViewById(R.id.mainAdLayout);

// Add the adView to it
layout.addView(adView);

AdRequest adRequest = new AdRequest();
adRequest.addTestDevice("<my device id>");
adRequest.addTestDevice(AdRequest.TEST_EMULATOR);

adView.loadAd(adRequest);

无论我做什么,广告都不会在 2.3 上加载。有任何想法吗?

这就是我在我的应用程序或 admob 的 logcat 中看到的全部内容:

I/Ads     ( 3220): adRequestUrlHtml: <html><head><script src="http://media.admob.com/sdk-core-v40.js"></script><script>AFMA_getSdkConstants();AFMA_buildAdURL({"kw":[],"preqs":0,"session_id":"16659815784493691135","u_sd":1.5,"seq_num":"1","slotname":"5ae6fdb32cdf4c1a","u_w":320,"msid":"com.havens1515.autorespondfree","js":"afma-sdk-a-v6.2.1","mv":"8011016.com.android.vending","isu":"B78F2F5C240A24F31F6EF9D6EBD74706","cipa":1,"bas_off":0,"format":"320x50_mb","oar":0,"net":"wi","app_name":"17.android.com.havens1515.autorespondfree","hl":"en","ad_pos":{"height":0,"visible":0,"y":0,"x":0,"width":0},"gnt":6,"u_h":569,"carrier":"31000","bas_on":0,"ptime":0,"u_audio":1});</script></head><body></body></html>

W/asset   ( 3220): deep redirect failure from 0x0103003e => 0x02060007, defStyleAttr=0x0101006c, defStyleRes=0x01030019, style=0x00000000

D/dalvikvm( 3220): GC_CONCURRENT freed 225K, 49% free 2928K/5639K, external 513K/519K, paused 2ms+7ms

D/dalvikvm( 3220): GC_EXTERNAL_ALLOC freed 2K, 49% free 2925K/5639K, external 513K/519K, paused 55ms

D/ViewConsistency( 3220): AbsListView android.widget.ListView@40516210 enabled= true

D/ViewConsistency( 3220): AbsListView android.widget.ListView@40516210 enabled= true

然后

I/Ads     ( 3220): To get test ads on this device, call adRequest.addTestDevice("B78F2F5C240A24F31F6EF9D6EBD74706");

I/Ads     ( 3220): adRequestUrlHtml: <html><head><script src="http://media.admob.com/sdk-core-v40.js"></script><script>AFMA_getSdkConstants();AFMA_buildAdURL({"preqs":1,"session_id":"16659815784493691135","u_sd":1.5,"seq_num":"2","slotname":"5ae6fdb32cdf4c1a","u_w":320,"msid":"com.havens1515.autorespondfree","js":"afma-sdk-a-v6.2.1","mv":"8011016.com.android.vending","isu":"B78F2F5C240A24F31F6EF9D6EBD74706","cipa":1,"bas_off":0,"format":"320x50_mb","oar":0,"net":"wi","app_name":"17.android.com.havens1515.autorespondfree","hl":"en","ad_pos":{"height":0,"visible":0,"y":0,"x":0,"width":0},"gnt":6,"u_h":569,"carrier":"31000","bas_on":0,"ptime":400,"u_audio":1});</script></head><body></body></html>

D/dalvikvm( 3505): Debugger has detached; object registry had 1 entries

W/ActivityThread( 3505): Application com.havens1515.autorespondfree can be debugged on port 8100...

D/szipinf ( 3505): Initializing inflate state

E/dalvikvm( 3505): Could not find class 'android.app.Notification$Builder', referenced from method com.havens1515.autorespondfree.AutoRespond.showNotification

W/dalvikvm( 3505): VFY: unable to resolve new-instance 15 (Landroid/app/Notification$Builder;) in Lcom/havens1515/autorespondfree/AutoRespond;

D/dalvikvm( 3505): VFY: replacing opcode 0x22 at 0x0031

D/dalvikvm( 3505): VFY: dead code 0x0033-00cd in Lcom/havens1515/autorespondfree/AutoRespond;.showNotification (Landroid/content/Context;)V

D/dalvikvm( 3505): GC_EXTERNAL_ALLOC freed 62K, 50% free 2706K/5379K, external 0K/0K, paused 40ms

I/Database( 3505): sqlite returned: error code = 0, msg = Recovered 14 frames from WAL file /data/data/com.havens1515.autorespondfree/databases/webview.db-wal

I/Database( 3505): sqlite returned: error code = 0, msg = Recovered 18 frames from WAL file /data/data/com.havens1515.autorespondfree/databases/webviewCache.db-wal

I/Ads     ( 3505): To get test ads on this device, call adRequest.addTestDevice("B78F2F5C240A24F31F6EF9D6EBD74706");

W/asset   ( 3505): deep redirect failure from 0x0103003e => 0x02060007, defStyleAttr=0x0101006c, defStyleRes=0x01030019, style=0x00000000

D/dalvikvm( 3505): GC_CONCURRENT freed 204K, 49% free 2926K/5639K, external 513K/519K, paused 2ms+4ms

D/dalvikvm( 3505): GC_EXTERNAL_ALLOC freed 24K, 49% free 2902K/5639K, external 513K/519K, paused 51ms

I/Ads     ( 3505): adRequestUrlHtml: <html><head><script src="http://media.admob.com/sdk-core-v40.js"></script><script>AFMA_getSdkConstants();AFMA_buildAdURL({"kw":[],"preqs":0,"session_id":"212234885725326360","u_sd":1.5,"seq_num":"1","slotname":"5ae6fdb32cdf4c1a","u_w":320,"msid":"com.havens1515.autorespondfree","js":"afma-sdk-a-v6.2.1","mv":"8011016.com.android.vending","isu":"B78F2F5C240A24F31F6EF9D6EBD74706","cipa":1,"bas_off":0,"format":"320x50_mb","oar":0,"net":"wi","app_name":"17.android.com.havens1515.autorespondfree","hl":"en","ad_pos":{"height":0,"visible":0,"y":0,"x":0,"width":0},"gnt":6,"u_h":569,"carrier":"31000","bas_on":0,"ptime":0,"u_audio":1});</script></head><body></body></html>
D/ViewConsistency( 3505): AbsListView android.widget.ListView@40536910 enabled= true

D/ViewConsistency( 3505): AbsListView android.widget.ListView@40536910 enabled= true

I/Ads     ( 3505): To get test ads on this device, call adRequest.addTestDevice("B78F2F5C240A24F31F6EF9D6EBD74706");

I/Ads     ( 3505): adRequestUrlHtml: <html><head><script src="http://media.admob.com/sdk-core-v40.js"></script><script>AFMA_getSdkConstants();AFMA_buildAdURL({"preqs":1,"session_id":"212234885725326360","u_sd":1.5,"seq_num":"2","slotname":"5ae6fdb32cdf4c1a","u_w":320,"msid":"com.havens1515.autorespondfree","js":"afma-sdk-a-v6.2.1","mv":"8011016.com.android.vending","isu":"B78F2F5C240A24F31F6EF9D6EBD74706","cipa":1,"bas_off":0,"format":"320x50_mb","oar":0,"net":"wi","app_name":"17.android.com.havens1515.autorespondfree","hl":"en","ad_pos":{"height":0,"visible":0,"y":0,"x":0,"width":0},"gnt":6,"u_h":569,"carrier":"31000","bas_on":0,"ptime":268,"u_audio":1});</script></head><body></body></html>

W/webcore ( 3505): Can't get the viewWidth after the first layout

W/webcore ( 3505): Can't get the viewWidth after the first layout

在跟踪广告行为时从 logcat 获得以下信息:

I/Ads     ( 5877): AdLoader timed out after 60000ms while getting the URL.

D/webviewglue( 5877): nativeDestroy view: 0x1e94e8

I/Ads     ( 5877): onFailedToReceiveAd(A network error occurred.)

D/AutoRespondFree( 5877): onFailedToReceiveAd (A network error occurred.)
4

2 回答 2

1

让您的班级实施AdListener,以便您可以在日志中获得有关请求发生情况的更多信息。

public class MyClass extends Activity implements AdListener {
  private static final String LOG_TAG = "MyClass";

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Get the ad.
    AdView adView = (AdView) findViewById(R.id.adView);

    // Set the AdListener.
    adView.setAdListener(this);

    // Your other code here.
    ...
  }

  /** Called when an ad is clicked and about to return to the application. */
  @Override
  public void onDismissScreen(Ad ad) {
    Log.d(LOG_TAG, "onDismissScreen");
    Toast.makeText(this, "onDismissScreen", Toast.LENGTH_SHORT).show();
  }

  /** Called when an ad was not received. */
  @Override
  public void onFailedToReceiveAd(Ad ad, AdRequest.ErrorCode error) {
    String message = "onFailedToReceiveAd (" + error + ")";
    Log.d(LOG_TAG, message);
    Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
  }

  /**
   * Called when an ad is clicked and going to start a new Activity that will
   * leave the application (e.g. breaking out to the Browser or Maps
   * application).
   */
  @Override
  public void onLeaveApplication(Ad ad) {
    Log.d(LOG_TAG, "onLeaveApplication");
    Toast.makeText(this, "onLeaveApplication", Toast.LENGTH_SHORT).show();
  }

  /**
   * Called when an Activity is created in front of the app (e.g. an
   * interstitial is shown, or an ad is clicked and launches a new Activity).
   */
  @Override
  public void onPresentScreen(Ad ad) {
    Log.d(LOG_TAG, "onPresentScreen");
    Toast.makeText(this, "onPresentScreen", Toast.LENGTH_SHORT).show();
  }

  /** Called when an ad is received. */
  @Override
  public void onReceiveAd(Ad ad) {
    Log.d(LOG_TAG, "onReceiveAd");
    Toast.makeText(this, "onReceiveAd", Toast.LENGTH_SHORT).show();
  }
}
于 2012-10-24T01:46:16.583 回答
0

我是个白痴。我在我的 Droid 2 上安装了一个我忘记的 adblock 应用程序(我已经有一段时间没有使用该设备了。)

很抱歉浪费您的时间!不过,我确实对您的答案投了赞成票,因为它确实帮助我意识到了问题所在。

于 2012-10-24T12:00:24.303 回答