Android method for generating money and inserting rice advertisements

Source: Internet
Author: User

Rice link http://www.youmi.net/register? R = mja0mzm =

Step 1 download the meter ad SDK and import the youmi-android.jar into the project where you want to embed the ad.

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 the directory path for the youmi-android.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 obtain precise user positioning information -->
<Uses-Permission Android: Name = "android. Permission. access_fine_location"/>
<! -- Use wifi to obtain precise user location information -->
<Uses-Permission Android: Name = "android. Permission. access_wifi_state"/>

Step 3: Add adactivity to androidmanifest. xml.

Adactivity is the carrier of advertisement display. Please add adactivity in androidmanifest. xml:
<Activity Android: Name = "net. youmi. Android. adactivity"
Android: configchanges = "keyboard | keyboardhidden | orientation"/>
<Meta-data Android: Name = "youmi_channel" Android: value = "0"/>

Step 4: Initialize account information.

Call admanager. INIT () in oncreate of the main activity to initialize parameters such as app id, app secret, request ad interval, and test mode (please call it once before any adview initialization ).
// The first parameter is your application release ID.
// The second parameter is your application password.
// The third parameter is the request interval. The valid value ranges from 30 to 200, in seconds.
// The fourth parameter is to set the test mode. If it is set to true, the test advertisement can be obtained. For official release, set this parameter to false.
Admanager. INIT (context, string appid, string appsec, int intervalsecond, Boolean istestmode );

! Note: In version 3.04, the parameters of the admanager. init method are changed to five, and the context parameter is added! In the debugging phase, set the test mode to true. Set the test mode to false and upload it to the website for review. ! Only test advertisements can be obtained for applications that have not been uploaded to the application installation package, applications that have not passed the review, and simulators that have passed the review, A real machine can get a normal advertisement.

The Code is as follows:

@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
// Application ID application password ad request interval (s) Test Mode
Admanager. INIT (this, "537ef88653a2993c", "b9e10bcfe994a9fb", 30, true );
Setcontentview (R. layout. Main );
}

Step 5: use XML layout to embed advertisements

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

<? XML version = "1.0" encoding = "UTF-8"?>
<Resources>
<Declare-styleable name = "net. youmi. Android. adview">
<! -- Ad background color [only valid for text ads] (value range: #000000 ---- # ffffff) -->
<ATTR name = "backgroundcolor" format = "color"/>
<! -- Ad text color [only valid for text ads] (value range: #000000 ---- # ffffff) -->
<ATTR name = "textcolor" format = "color"/>
<! -- Advertising background transparency [valid only for text ads]. The default value is 255. The value range is 0-255. -->
<ATTR name = "backgroundtransparent" format = "integer"/>
</Declare-styleable>
</Resources>

2. embed the rice advertisement view in the layout main. xml:

The following is an instance:
<? XML version = "1.0" encoding = "UTF-8"?>
<! -- You need to set the 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">
<Net. youmi. Android. adview
Android: Id = "@ + ID/adview"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Umadsdk: textcolor = "# ffffff"
Umadsdk: backgroundcolor = "# 4076aa"
Umadsdk: backgroundtransparent = "155" type = "regxph" text = "yourobjectname"/>
</Linearlayout>
Note: xmlns: umadsdk = "http://schemas.android.com/apk/res/your application package name" must be added, otherwise the editor will prompt an error.

3. xml layout Code Section

Import net. youmi. Android. admanager;
Import Android. App. activity;
Import Android. OS. Bundle;
Public class testadactivity extends activity {
/** Called when the activity is first created .*/
// Application ID application password ad request interval (s) Test Mode
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
// Application ID application password ad request interval (s) Test Mode
Admanager. INIT (this, "537ef88653a2993c", "b9e10bcfe994a9fb", 30, true );
Setcontentview (R. layout. Main );
}
}

The final running result is shown in:

Related Article

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.