2010-08-08 78 views
4
顯示在Android

我已經包括在我的清單中的相關部分:麻煩廣告在AdMob

<meta-data android:value="123456789" android:name="ADMOB_PUBLISHER_ID" /> 

      <!-- Track Market installs from AdMob ads -->    
      <receiver android:name="com.admob.android.ads.analytics.InstallReceiver" android:exported="true"> 
        <intent-filter> 
          <action android:name="com.android.vending.INSTALL_REFERRER" /> 
        </intent-filter> 
      </receiver> 
      <meta-data android:value="true" android:name="ADMOB_ALLOW_LOCATION_FOR_ADS" />' 

<uses-sdk android:minSdkVersion="3" /> 
<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>' 

ATTRS從一例子複製:

<?xml version="1.0" encoding="utf-8"?> 
    <resources> 
      <declare-styleable name="com.admob.android.ads.AdView"> 
        <attr name="backgroundColor" format="color" /> 
        <attr name="primaryTextColor" format="color" /> 
        <attr name="secondaryTextColor" format="color" /> 
        <attr name="keywords" format="string" /> 
        <attr name="refreshInterval" format="integer" /> 
      </declare-styleable> 
    </resources> 

我的佈局(這是一個標籤視圖順便說一句)是一個表在它自己的行:

xmlns:app="http://schemas.android.com/apk/res/com.icukansas.lenscalculator" 

<TableRow> 
    <!-- Place an AdMob ad at the bottom of the screen. --> 
    <!-- It has white text on a black background. --> 
    <com.admob.android.ads.AdView 
     android:layout_span="4" 
     android:id="@+id/ad" 
     app:backgroundColor="#000000" 
     app:primaryTextColor="#FFFFFF" 
     app:secondaryTextColor="#CCCCCC" 
     app:keywords="security" 
    /> 
    </TableRow> 

我然後調用:

public class myClass extends Activity implements AdListener{ 

公共無效的onCreate(捆綁savedInstanceState){ super.onCreate(savedInstanceState);

setContentView(R.layout.tab_thistab); 

    AdView ad = (AdView) findViewById(R.id.ad); 
    ad.setAdListener(this); 

每當我在日誌中遇到錯誤ToReceiveAd錯誤。

我敢肯定它的東西很容易我缺少:)

+0

這個問題使用attrs.xml,這可能意味着它使用Admob 4.0.4或更早的版本。 4.1.0在[此Google小組討論]中描述了一些變更(http://groups.google.com/group/google-admob-ads-sdk/browse_thread/thread/3b885d3fe5bb21a5)(查找Tim的帖子)。 – idbrii 2011-06-17 17:07:25

回答

1

是你缺少一點東西:

1.Most重要:

<meta-data android:value="a14e20856e4ad8f" android:name="ADMOB_PUBLISHER_ID" /> 

2.Refresh間隔:

<com.admob.android.ads.AdView  
      android:id="@+id/ad" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      myapp:backgroundColor="#000000" 
      myapp:primaryTextColor="#FFFFFF" 
      myapp:secondaryTextColor="#CCCCCC" 
      myapp:refreshInterval="30"   
    /> 

休息看起來很好。

+0

我有AndroidManifest中的第一個。我只是編了一些數字,但我的應用程序中有我的真實ID。 我已經添加刷新間隔到我的xml文件,仍然沒有運氣:( – Jason 2010-08-09 06:14:17

+0

我最終把廣告放在我的main.xml中,而不是標籤的xml和它的工作now.Never可以弄清楚爲什麼它不會請求在我的子活動中 – Jason 2010-08-09 23:52:03

+1

嘿,感謝發佈商ID現在我可以使用你的發佈! – JPM 2011-11-09 17:25:56

0

我有同樣的問題 - friggin tabview。將它放在主要活動中,而不是標籤完美運行。

1

我知道這是舊的,但我認爲這將有助於人們試圖在桌面佈局中投放廣告。我最終通過在我的TableLayout中包含android:stretchColumns =「0,1,2,3」來得到這個工作。如果你的跨度不是4,你可以在stretchColumns中放入與你的跨度相同數量的列/數字。

<TableLayout android:id="@+id/TableLayout01" android:stretchColumns="0,1,2,3" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> 
0

喜賈森 我有解決方案,可能會幫助 寫這段代碼在你的類

AdManager.setTestDevices(new String[] { AdManager.TEST_EMULATOR, // Android emulator 
       "5669B77A6042345BC23219DCAC6C15CA",// device id 
       }); 
ad = (AdView) findViewById(R.id.ad); 
ad.requestFreshAd(); 
ad.setAdListener(this); 

可以運行在信息標籤的應用程序後,logcat中獲得設備ID,搜索文本。

要在模擬器上使用AdManager.setTestDevices獲得測試廣告... 還成立聽衆

,你會得到你的設備ID,貼吧,否則你以前的代碼是完美的。

0

我已經嘗試過將近3個小時的問題了。我遵循所有谷歌的例子。最後,我知道了。您可以自定義請求,然後它將工作。在我的例子,我這​​樣做是在活動類:

AdRequest re = new AdRequest(); 
    //re.setTesting(true); 
    re.setGender(AdRequest.Gender.FEMALE); 
    adview.loadAd(re); 

你可以在這裏查看我的榜樣,我總是把我的APK,和源代碼。您可以下載,並嘗試:

Add Google Admob in Android Application

1

你忘了添加netstate許可清單中。