集成Admob的到Android问题问题、Admob、Android

2023-09-09 22:00:04 作者:予澈

我试图整合Admob的到Android,我最终没有成功。文件说需要提供的DeviceID获取广告为真正Devices.Could请你帮我这个。但我米设置AdManager.TestEmulator凑了仿真器的广告。

I am trying to integrate Admob to android, i end up with no success. The Document says Need to Provide DeviceID to get Ads for Real Devices.Could you please Help me about this. But I m getting ads in the Emulator by setting AdManager.TestEmulator.

推荐答案

这是相当简单的设置与AdMob的,我使用它在多个应用程序。一旦你确定你的AdMob的网站/控制面板上的应用程序,你会看到你的唯一ID应用程序。

It's fairly straight forward to setup with AdMob, I'm using it on several applications. Once you define you application on the AdMob website/control panel you will see your unique ID for your application.

然后你只需要对AdMob的JAR添加到您的项目,假设你使用Eclipse的最简单方法是在你的项目文件夹中创建一个libs文件夹,复制AdMob的罐子在那里,从偏食,右键单击它,去构建路径/添加到构建路径。

Then you just need to add the AdMob Jar to your project, assuming you're using eclipse easiest way is to create a libs folder in your project folder, copy the admob jar in there and from eclipse, right click it, and go to Build Path/Add to Build Path.

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

Then open your manifest file and add the following somewhere inside the tag

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

下一步决定你想广告的出现,我一般都是把广告权在的LinearLayout的底部,所以添加的活动如下..

Next decide which activity you wish the ad's to appear, I usually place the ad right at the bottom of a LinearLayout so add the following..

<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命名空间,你会看到顶部

At the top of your layout definition where you define your xml namespace you will see

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

还添加了一个引用AdMob的命名空间,这样你将有:

also add a reference to the admob namespace so you will have :

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 中的值文件夹中的文件,并插入以下内容:

Finally create a file named attrs.xml in the values folder and insert the following :

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

那你应该是好去,我当然也没有必要做任何真正的设备不同,而不是模拟器,上面应该为你工作。你并不总能看到的广告尤其是前几次运行的应用程序,但如果你看到AdMob的条目在你的logcat输出,当你运行你的应用程序,然后你就可以确信它的工作。

Then you should be good to go, I certainly haven't needed to do anything different for real devices as opposed to the emulator, the above should work for you. You don't always see ad's especially the first few times you run the app but if you are seeing ADMOB entries in your logcat output when you run your app then you can be confident it's working.

问候