2011-08-09 36 views
5

我只是想讓admob運行並測試不同的「工作」代碼示例。 他們都沒有工作。不要讓AdMob在模擬器上運行(android 2.2)

在活動中,我有:

的OnCreate()

AdView ad = (AdView) findViewById(R.id.ad); 
    AdRequest r = new AdRequest(); 
    r.addTestDevice("X3XFX518X7DE1FD879XA5XXAX1AX8BXX"); //no clue why this string 
    ad.loadAd(r); 

在我已插入視圖定義如下(是不是myPubID有實際上我真正的PUB ID):

<com.google.ads.AdView 
    android:id="@+id/ad" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    ads:adUnitId="<myPubID>" 
    ads:adSize="BANNER"/> 

我得到的是1秒黑屏。

以下日誌(logcat的)執行

08-09 10:45:03.527: INFO/ActivityManager(59): Start proc de.syrtec.android.bogloid for activity de.syrtec.android.bogloid/.StartSeite: pid=4402 uid=10043 gids={3003} 
08-09 10:45:04.887: ERROR/Ads(4402): Could not get currentAdManager. 
08-09 10:45:05.397: WARN/InputManagerService(59): Window already focused, ignoring focus gain of: [email protected] 
08-09 10:45:05.567: INFO/Ads(4402): To get test ads on this device, call adRequest.addTestDevice(AdRequest.TEST_EMULATOR); 
08-09 10:45:06.159: INFO/Ads(4402): adRequestUrlHtml: <html><head><script src="http://www.gstatic.com/afma/sdk-core-v40.js"></script><script>AFMA_buildAdURL({"preqs":0,"u_sd":1.5,"slotname":"********;</script></head><body></body></html> 
08-09 10:45:07.528: WARN/webcore(4402): Can't get the viewWidth after the first layout 
08-09 10:45:07.848: INFO/Ads(4402): Received ad url: <"url": "http://r.admob.com:80/ad_source.php?preqs=0&u_sd=1.5&slotname=*****: "null"> 
08-09 10:45:08.809: DEBUG/webviewglue(4402): nativeDestroy view: 0x2bbb30 
08-09 10:45:08.818: INFO/Ads(4402): onFailedToReceiveAd(Ad request successful, but no ad returned due to lack of ad inventory.) 
08-09 10:45:11.168: DEBUG/dalvikvm(3148): GC_EXPLICIT freed 32 objects/1640 bytes in 131ms 
08-09 10:45:16.237: DEBUG/dalvikvm(272): GC_EXPLICIT freed 195 objects/12168 bytes in 137ms 

我使用GoogleAdMobAdsSdk-4.1.1.jar和仿真器的Android 2.2中被打印。

在我的AdMob帳戶沒有過濾和AdSense被激活。

我也嘗試過通過instanciating AdView中,並將其與增加了rootlayout: (指http://code.google.com/mobile/ads/docs/android/fundamentals.html

AdView adView = new AdView(this, AdSize.BANNER, "PUB_ID"); 
LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout); 
layout.addView(adView); 
adView.loadAd(new AdRequest()); 

,並得到了與以下日誌相同的行爲:

08-09 10:49:18.367: INFO/ActivityManager(59): Start proc de.syrtec.android.bogloid for activity de.syrtec.android.bogloid/.StartSeite: pid=4543 uid=10043 gids={3003} 
08-09 10:49:19.297: ERROR/Ads(4543): Could not get currentAdManager. 
08-09 10:49:19.797: WARN/ActivityManager(59): Activity pause timeout for HistoryRecord{44fe4350 de.syrtec.android.bogloid/.StartSeite} 
08-09 10:49:20.067: INFO/Ads(4543): To get test ads on this device, call adRequest.addTestDevice(AdRequest.TEST_EMULATOR); 
08-09 10:49:20.379: INFO/Ads(4543): adRequestUrlHtml: <html><head><script src="http://www.gstatic.com/afma/sdk-core-v40.js"></script*****;</script></head><body></body></html> 
08-09 10:49:20.397: WARN/InputManagerService(59): Window already focused, ignoring focus gain of: [email protected] 
08-09 10:49:22.737: WARN/webcore(4543): Can't get the viewWidth after the first layout 
08-09 10:49:22.957: INFO/Ads(4543): Received ad url: <"url": "http://r.admob.com:80/ad_source.php?preqs=0&u_sd=1.5&slotname=***** "null"> 
08-09 10:49:24.038: DEBUG/dalvikvm(4543): GC_FOR_MALLOC freed 3826 objects/234984 bytes in 154ms 
08-09 10:49:24.058: DEBUG/webviewglue(4543): nativeDestroy view: 0x2c5320 
08-09 10:49:24.058: INFO/Ads(4543): onFailedToReceiveAd(Ad request successful, but no ad returned due to lack of ad inventory.) 
08-09 10:49:24.078: DEBUG/webviewglue(4543): nativeDestroy view: 0x2b81d0 

有沒有人有線索?

回答

5

我試圖像在建議教程(blog.kerul.net/2011/05/

,但我只得到一個黑色的觀點一秒鐘,然後返回到Android的「桌面」:

現在

來源是這樣的:

活動類:

class StartActivity extends AdActivity{ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.main); 

    AdView adview = (AdView)findViewById(R.id.adView1); 
    AdRequest re = new AdRequest(); 
    re.addTestDevice(AdRequest.TEST_EMULATOR); 
    re.setTesting(true); 
    adview.loadAd(re); 
} 
... 
} 

的觀點:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
android:orientation="vertical" android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

    <com.google.ads.AdView 
     xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
     android:id="@+id/adView1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     ads:adSize="BANNER" 
     ads:adUnitId="MY_PUB_ID" /> 

</LinearLayout> 

是的,我換成MY_PUB_ID與我真正的發佈者ID

有什麼缺失? 你使用哪個Android運行時模擬器?

+0

嗯......非常有趣。這是你的所有項目,還是有更多的代碼?首先刪除你的re.addTestDevice(Adrequest.TEST_EMULATOR);如果使用re.setTesting(true)行,則不需要。您是否嘗試在Eclipse中創建另一個項目,或者這是第一個?問題可能不在於代碼,而在於Eclipse。 – Zwiebel

+0

謝謝:-) ..現在測試廣告顯示打印「成功!現在您已準備好通過應用程序Galaxy」 那麼如何繼續實際的廣告? 我會做這樣的: 1.刪除re.setTesting(真) 2.發佈我的應用程序市場上AdMob的 3.聯動app的應用 的實際市場真實的URL是仍然存在缺少或不正確的東西? –

+0

終於:D問題是什麼?你只是刪除了re.addTestDevice?是的,首先需要從項目中刪除re.setTesting(true)行,然後發佈它。我認爲你不需要實際的市場網址,你只需要將你的軟件包名稱寫入示例,就可以看到admob網站上顯示的內容。我很高興我可以幫你;) – Zwiebel

1

你需要放置到//不知道爲什麼這個字符串測試設備的代碼。我更喜歡在測試時使用setTesting(true),但你知道。問題可能在於此。

哦,我明白了,你的程序不能在com.google.ads.adView部分接收廣告,因爲廣告資源的故障 將此放在您的佈局: 的xmlns:廣告=「HTTP:/ /schemas.android.com/apk/lib/com.google.ads」

而且別忘了帶上互聯網的權限,以您的清單。

希望它有幫助。

編輯:我不知道,這是你的問題,但我認爲它可以幫助。

+0

我喜歡設定r.addTestdevice(phoneID)測試設備也是如此,那麼我開發的手機接收測試廣告,我也不需要恢復setTesting( )當我釋放時爲False。另外,如果您使用多個開發人員手機和模擬器,則只需添加他們的ID並完成即可。至於「/ /無線索...」,這條線沒有問題:-) – Smugrik

+0

感謝您的答案..我試着它像你建議..並得到了相同的行爲和我的第二個日誌輸出最初的帖子 –

+0

可能它會幫助: http://blog.kerul.net/2011/05/installing-google-admob-into-android.html 至少我希望:) – Zwiebel

0

缺少廣告資源意味着AdMob沒有任何可投放的廣告,如果您的帳戶是新的,這種情況通常會發生,一段時間後您的填充率會提高並且會投放更多廣告。 如果您在您的AdMob網站/應用頁面看到一個綠色的狀態指示燈,你不應該擔心 嘗試將AdSense來增加您的填充率Enabling Google AdSense Ads in Your Applications

編輯:想你已經有了啓用了AdSense

+0

我得到了一個綠色狀態通知: 活動:您的網站當前正在向AdMob發送查看請求。 (我不明白爲什麼我的網站正在與admob聊天...) 我可以做任何事情來提高填充率..要獲得一個單一的廣告顯示?...什麼是實際上連接到我的網站作爲它與我的應用程序無關? –

+0

您的網站是admob用於出版物,應用移動網站等的通用術語......所以這意味着您的應用正在與admob – Smugrik

+0

進行通信,因此我的網站網址僅用作我的應用的標識符嗎? –

0

我有這樣的應用程序崩潰和顯示這樣的消息 - 「錯誤膨脹類com.admob.ads.AdView」的經驗。做一些研究和測試我得出以下XML屬性來顯示AdView;

`<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="match_parent" 
android:background="@drawable/bg1" 
android:orientation="vertical" > 

<TableRow 
    android:id="@+id/tableRow2" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 
    <com.google.ads.AdView 
     xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
     android:id="@+id/ad" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     ads:adSize="SMART_BANNER" 
     ads:adUnitId="738a44d913034b9f" 
     /> 
</TableRow> 

<TableRow 
    android:id="@+id/tableRow3" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

    <EditText 
     android:id="@+id/txtsearch" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:inputType="textMultiLine" 
     android:maxLines="3" 
     android:minLines="1" 
     android:scrollbarStyle="outsideOverlay" 
     android:scrollbars="vertical" /> 

</TableRow> 

<TableRow 
    android:id="@+id/tableRow1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 







    <Button 
     android:id="@+id/btnkamus" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:drawableRight="@drawable/search" /> 




    <Button 
     android:id="@+id/btnsearch" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:text="Kesan" /> 


    <Button 
     android:id="@+id/btncadang" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:text="Cadang" /> 

</TableRow> 


<WebView 
    android:id="@+id/webView1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

</LinearLayout>` 

完全教程是在這裏 - http://blog.kerul.net/2012/08/example-how-to-install-google-admob-6x.html

相關問題