Android profit-making path (5)-embedding domob ads on the Interface

Source: Internet
Author: User

Recently I made a small app and embedded the advertisement on the domob ad platform. The following is a summary of how to embed the advertisement:

My Sina Weibo (wind Swiss): http://weibo.com/tianrui1990

Step 1: Download The domob ad SDK and import domob_android_sdk.jar to the project where the advertisement is to be embedded.

1. Right-click your project root directory and choose Properties"
2. Select "Java build path" on the left panel"
3. Select the "Libraries" tab.
4. Click "add external jars „"
5. Select
Directory path of domob_android_sdk.jar.
6. Click "OK". The import is successful.

Step 2: Configure user permissions in the androidmanifest. xml file.

Be sure to configure the following permissions. Otherwise, the advertisement may not be obtained.
1. Android. Permission. Internet, connected to the internet permission, used to request Advertisement
2. Android. Permission. read_phone_state, used to accurately collect the system information of users' mobile phones
3. Android. access_network_state, used to precisely identify network access points and other information
4. Android. Permission. access_coarse_location helps to accurately serve regional ads and help collect regional distribution statistics of users who use applications
5. Android. Permission. write_external_storage helps to cache image resources, save traffic, and provide a better user experience.

Copy the following permission configuration code to the androidmanifest. xml file:

<! -- Permission that must be affirmed --> <uses-Permission Android: Name = "android. permission. internet "/> <uses-Permission Android: Name =" android. permission. read_phone_state "/> <uses-Permission Android: Name =" android. permission. access_network_state "/> <uses-Permission Android: Name =" android. permission. access_coarse_location "/> <uses-Permission Android: Name =" android. permission. write_external_storage "/> <! -- The following are optional permissions --> <! -- Use GPS to get the user's precise positioning information --> <uses-Permission Android: Name = "android. Permission. access_fine_location"/> <! -- Use wifi to get the user's precise positioning information --> <uses-Permission Android: Name = "android. Permission. access_wifi_state"/>

Step 3: add the activity declaration to androidmanifest. xml.

Before adding the </Application> label in the androidmanifest. xml file, you must add the following activity declaration:

<Activity Android: Name = "cn. domob. Android. Ads. domobactivity"
Android: theme = "@ Android: style/theme. translucent"/>

Step 4: add the publisher ID.

Add the PID statement before the </Application> label in the androidmanifest. xml file. If the publisher ID you applied for on the domob website is 999999 #123, you need to add the PID statement in androidmanifest. xml
Add the following line to the file:

<meta-data android:value="999999#123" android:name="DOMOB_PID" /><meta-data android:value="false" android:name="DOMOB_TEST_MODE"/>

Note: In <meta-data Android: value = "false" Android: Name = "domob_test_mode"/>, set Android: value = "true ", changed to Android: value = "false" during official release or upload ".

Step 5: use XML layout to embed advertisements

1. Add attrs. XML to the res/values folder. If you do not add this file, you cannot set the display ad attribute in layout. The content of the attrs. xml file is as follows:

<?xml version="1.0" encoding="UTF-8"?><resources><declare-styleable name="cn.domob.android.ads.DomobAdView">     <attr name="backgroundColor" format="color" />    <attr name="primaryTextColor" format="color" />    <attr name="keywords" format="string" />    <attr name="spots" format="string" />    <attr name="refreshInterval" format="integer" />    </declare-styleable></resources>

2. embed the ad view in the layout main. xml:

The following is an instance:

<? XML version = "1.0" encoding = "UTF-8"?> <! -- Need to set namespace: umadsdk --> <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" xmlns: umadsdk = "http://schemas.android.com/apk/res/com.youmi" Android: Orientation = "vertical" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent"> <CN. domob. android. ads. domobadview Android: Id = "@ + ID/domobad" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" MyApp: KEYWORDS = "game" MyApp: refreshinterval = "20"/> </linearlayout>

Note: xmlns: umadsdk = "http://schemas.android.com/apk/res/your application package name" must be added, otherwise the editor will prompt an error.


My Sina Weibo (wind Swiss): http://weibo.com/tianrui1990

Original Author: Wind Rui

Please mark the original author and address for reprinting. Thank you!


The final running result is shown in:

My Sina Weibo (wind Swiss): http://weibo.com/tianrui1990

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.