2010-10-26 64 views
1

我正在尝试将Admob集成到Android,但最终我没有成功。该文件表示需要提供DeviceID以获取真实设备的广告。请您帮我解决这个问题。但我通过设置AdManager.TestEmulator在模拟器中获得广告。将Admob集成到Android问题

+0

关于AdMob的,你应该检查这太HTTP:/ /stackoverflow.com/questions/5507516/admob-and-how-does-it-work/32963340#32963340 – justLearning 2015-10-06 10:58:44

回答

6

使用AdMob进行设置非常简单,我在多个应用程序上使用它。一旦您在AdMob网站/控制面板上定义了您的应用程序,您将看到您的应用程序的唯一ID。

然后,您只需将AdMob Jar添加到您的项目中,假设您使用的是eclipse,最简单的方法是在您的项目文件夹中创建一个libs文件夹,将admob jar复制到eclipse中,右键单击它,并转到构建路径/添加到构建路径。

然后打开你的manifest文件,并添加以下的地方,在标签内

<meta-data android:value="<YOUR APPLICATION ID FROM ADMOB CONTROL PANEL>" android:name="ADMOB_PUBLISHER_ID" /> 

下一步决定你希望广告出现哪些活动,我通常放置广告权在的LinearLayout的底部,所以加下面..

<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" 
    /> 

,在您定义XML命名空间的布局定义的顶部,你会看到

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

也增加了AdMob的命名空间的引用,所以你将有:

xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:myapp="http://schemas.android.com/apk/res/net.dbws.fv" **<-- change package (net.dbws.fv) to your package** 

最后创造价值的文件夹命名为attrs.xml一个文件,并插入以下内容:

<?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> 

然后你应该是好的去,我真的不需要做任何不同的真实设备,而不是模拟器,上述应该为你工作。您不会总是看到广告,特别是您运行应用程序的前几次,但如果您在运行应用程序时看到logcat输出中的ADMOB条目,那么您可以确信它正在工作。

问候

+0

很好的解释戴夫:)。非常感谢您,但我想知道链接的位置,以获取adMob的唯一ID,以及我在哪里可以找到adMob.jar。提前致谢 – Houcine 2011-07-13 13:52:04

2

从“网站&应用程序”的概述,当你登录到AdMob中,将鼠标悬停在您的应用程序的名称。您应该看到两个按钮,“报告”和“管理设置”。 点击“管理设置”。我认为这就是'控制面板'所指的意思。

您会在页面顶部看到“发布商ID”。这就是你的AndroidManifest.xml文件所需要的,取代“YOUR_ID_HERE”。

字符串“ADMOB_PUBLISHER_ID”保持原样。

0

嗨亲爱找到简单的步骤,在应用程式中加入AdMob广告...

1-下载GoogleAdMobAdsAdk-6.4.1。

2-将其粘贴到lib文件夹中。

3-转到https://apps.admob.com/?pli=1#monetize/adunit:create

4-选择货币化新的应用选择从这里得到您的ID

5改变你的布局文件 -

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity" > 




    <com.google.ads.AdView 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:id="@+id/adView" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
ads:adSize="BANNER" 
ads:loadAdOnCreate="true" 

ads:adUnitId="Your Unit Id you generated" 
/> 

</RelativeLayout> 

6- 把这些权限在Android清单文件

<uses-permission android:name="android.permission.INTERNET"/> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 

享受