2012-10-23 72 views
0

我有一個Android應用程序,我試圖展示廣告。廣告在我的Galaxy Nexus上顯示正常,運行Android 4.1.2,但在我的Droid 2上運行Android 2.3時,它們不顯示顯示。Android 2.3中的Admob

我看了所有的地方,我想不出我做錯了什麼

Android清單:

<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上加載。有任何想法嗎?

這是我在logcat中看到我的應用程序或AdMob:

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 [email protected] enabled= true 

D/ViewConsistency(3220): AbsListView [email protected] 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 [email protected] enabled= true 

D/ViewConsistency(3505): AbsListView [email protected] 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.) 
+0

代碼很好,我們需要看到LogCat輸出。有沒有崩潰?它是一個網絡錯誤(在您的2.3設備上沒有互聯網?AdRequest成功,但缺乏庫存(您沒有在2.3設備上添加TestDevice,並且您的帳戶尚未獲得實時廣告) –

+0

我曾看過logcat。沒有崩潰,logcat中沒有錯誤,我在2.3設備上連接了互聯網(連接到無線網絡,並且正在接收電子郵件,因此它已被驗證正在工作),該帳戶已在4.1.2設備上獲得實時廣告。我在這裏完全傻了,謝謝你的試用: -/ – Randy

+0

你可以粘貼日誌嗎?必須有一些相關的東西,如果確實沒有什麼,可能是一個請求甚至沒有被製作? –

回答

0

我是個白癡。我在我的Droid 2上安裝了一個adblock應用程序,我忘記了它(我在相當一段時間內沒有使用過該設備)。

對不起,浪費你的時間!儘管我確實投了你的答案,因爲它幫助我意識到問題所在。

+1

這不是很諷刺嗎? :) –

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(); 
    } 
} 
+0

檢查我最後的編輯。沒有從它輸出。不知道發生了什麼事。 – Randy

+0

你是否通過'adView.setAdListener(this)設置了adlistener;'? –

+0

杜,愚蠢的錯誤哈哈。現在就這樣做。 – Randy