Getting Started with AdMob Android Ads
This page will help you get started with becoming a publisher for AdMob Android Ads.

[edit]Learn about AdMob Android ads
AdMob Android ads are a turnkey ad unit for monetizing Android Apps
The ad dimensions on the T-Mobile G1 are: 320 pixels wide x 48 pixels tall
[edit]Sign up with AdMob
1. Register or login at admob.com, and click 'Sites & Apps".

2. Click "Add Mobile Site", and provide the info for your Android App.

3. Once you've added your site, click "Install Code". You should see a button to download the Android SDK.

4. The download includes the binaries, documentation, and a sample.

1. Review README.txt
2. Read documentation/index.html which details how to integrate AdMob ads into your application
3. Look at the Lunar Lander sample project to see a working example
[edit]AdMob Android SDK
The AdMob Android SDK contains the code necessary to install AdMob ads within your application.

[edit]SDK Integration Instructions
(1) In your project's root directory create a subdirectory libs. This will already be done for you if you used Android's activitycreator tool. Copy the AdMob Jar file into that libs directory.

For Eclipse projects:

Go to the Properties of your project (right-click on your project from the Package Explorer tab and select Properties)
Select "Java Build Path" from left panel
Select "Libraries" tab from the main window
Click on "Add JARs..."
Select the JAR copied to the libs directory
Click "OK" to add the SDK to your Android project
(2) Add your publisher ID to your AndroidManifest.xml . Just before the closing </application> tag add a line to set your publisher ID. If you publisher ID were, “a149afxxxx”, the line would look like this:

<meta-data android:value="a149afxxxx" android:name="ADMOB_PUBLISHER_ID" />
</application>
To find your publisher ID, log into your AdMob account, select the “Sites & Apps” tab, and click on the “Manage Settings” link for your site. On this page, you can find your publisher ID (screenshot below).

(3) Add the INTERNET permission to your AndroidManifest.xml just before the closing </manifest> tag:

<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Optionally, you can add the ACCESS_COARSE_LOCATION and/or ACCESS_FINE_LOCATION permissions to allow AdMob the ability to show geo-targeted ads.

(4) Paste the following into your attrs.xml file:

<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>
If your project does not already have an attrs.xml file, then create one in the /res/values/ directory, and paste 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>

(5) Create a reference in to the attrs.xml file in your layout element by adding xmlns line that includes your package name specified in AndroidManifest.xml. For example, if your package name were com.example.SampleApp, you would include this line:

xmlns:myapp="http://schemas.android.com/apk/res/com.example.SampleApp"
So for a simple screen with only one ad, your layout element would look like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/com.example.SampleApp"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<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"
/>
</LinearLayout>

(6) When integrating AdMob ads into your application it is recommended to use test mode. In test mode test, ads are always returned.

Test mode is enabled on a per-device basis. To enable test mode for a device, first request an ad, then look in LogCat for a line like the following:

To get test ads on the emulator use AdManager.setTestDevices...
Once you have the device ID you can enable test mode by calling AdManager.setTestDevices:

AdManager.setTestDevices( new String[] {
AdManager.TEST_EMULATOR, // Android emulator
"E83D20734F72FB3108F104ABC0FFC738", // My T-Mobile G1 Test Phone
} );
}

Once you’ve successfully requested test ads, try clicking on each type of test ad to make sure it works properly from your application. The type of test ad returned is changed with AdManager.setTestAction.




[edit]FAQ
Q: I think I've done everything correctly, but I'm not seeing any ads. What's up with that?

A: You should be seeing a "DidRequestAd" message in your application log. This means that an ad request was made to AdMob, but there was no matching ad to serve in your application. Your integration should be working, and there's nothing else you need to do. If this doesn't work, try the following:

1. Request an ad in test mode.

2. Double-check that your publisher id is set correctly and try again.

3. For the SDK, check whether the included sample projects displays ads. If it does, you might want to check that you are displaying the ad correctly on screen.

4. Confirm that there are ads available for your site by logging in to www.admob.com.

5. Also, the very first request to the AdMob adservers can sometimes take a while; if all else fails, wait 5-10 minutes and try again.

6. If this still doesn't work, email support@admob.com.

Q: Where does the market URL come from?

A: The Android Market URL for your application will be http://market.android.com/search?q=pname: followed by your application's classpath. For example: http://market.android.com/search?q=pname:com.example.ExampleApp

Retrieved from "http://developer.admob.com/wiki/Android"

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android studio 打不开官方虚拟机 100%成
  2. Android中 ScrollView(ListView)中嵌套List
  3. Android之toolbar的使用
  4. Android线程池
  5. Android学习-RecyclerView默认scrollbar
  6. 输入法软键盘搜索执行两次的解决方法
  7. Android(安卓)系统入门
  8. Arcgis android 10.2安装方法
  9. 2.3.1TextView控件
  10. Android原生(Native)C(JNI/NDK)开发之二:f