Insert ads in Android apps and simple examples _android

Source: Internet
Author: User

Presumably everyone knows that domestic Android apps are basically free, so how do developers get paid? The application of the insertion of advertising is a relatively common means of profit. This article explains how to insert ads in Android apps.

The domestic advertising platform has many, the user quantity is more than has the Wanpo, has the meter, the big pu. The following will not be introduced, lest I advertise. This paper takes Wanpo as an example.

1, first to the universal website Download SDK, the SDK inside the jar package into the project's Lib directory.

2, modify the Androidmanifest.xml file.

Make sure that the application has the following permissions:

xml/html Code

<uses-permission android:name= "Android.permission.INTERNET"/>    
<uses-permission android:name= " Android.permission.ACCESS_NETWORK_STATE "/>   
<uses-permission android:name=" android.permission.ACCESS_ Wifi_state "/>   
<uses-permission android:name= android.permission.READ_PHONE_STATE"/>   
< Uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>    
<uses-permission android: Name= "Android.permission.GET_TASKS"/> 
   
<!--The following two permissions are optional to support ad-hoc forms-->    
<uses-permission android : Name= "Com.android.launcher.permission.INSTALL_SHORTCUT"/>   
<uses-permission android:name= " Com.android.browser.permission.WRITE_HISTORY_BOOKMARKS "/> 

Add the following in the <application> section:

xml/html Code

<activity android:name= "Com.waps.OffersWebView" android:configchanges= "keyboardhidden|orientation"/> 
   
<!--The following properties for the application ID, from the Wanpo background to get-->    
<meta-data android:name= "waps_id" android:value= "application identification, which you WANPO apply for an application will generate"/ > 
   
<!--The following property is the distribution channel ID, the encoding table refer to-->    
<meta-data android:name= "waps_pid" android:value= "distribution channel identification at the end of this document. You need to release channels such as Jifeng, Android Market "/> 

3, Interface code

(i) Data statistics interface

This interface is the basis for normal use of all other interfaces and must be invoked each time the application is started in order to ensure accurate statistical data.

Step 1: In the first activity class in the application (the first class that starts), add the following line of code:

Java code

Mode ①: Read waps_id and Waps_pid appconnect.getinstance (this) through androidmanifest files  
;   You must ensure that the WAPS_ID//mode is configured in the Androidmanifest file  
   
②: waps_id and Waps_pid  
appconnect.getinstance ("waps_id", "WAPs") are set by code. _pid ", this);   

Step 2: In the processing method of the program exit, add the following line of code:

Java code

The following methods will be used to release the system resource Appconnect.getinstance (this) that the SDK occupies  
. Finalize (); 

4, the advertising bar to add

Add in Layout file:

xml/html Code

<linearlayout 
android:id= "@+id/adlinearlayout" 
android:layout_width= "Fill_parent" 
android: layout_height= "Wrap_content" 
android:gravity= "Center_horizontal"/> 

Add the following code to the activity:

Java code

LinearLayout container = (linearlayout) Findviewbyid (r.id.adlinearlayout);  
New Adview (This,container). Displayad (); 

5, mini advertising bar to add

Step 1: Copy the following code into the corresponding Activiy layout file and place it in the appropriate location:

xml/html Code

<linearlayout android:id= "@+id/miniadlinearlayout"    
       android:layout_width= "Wrap_content"    
       android: layout_height= "Wrap_content"    
    android:gravity= "Center_horizontal"/> 

Step 2: In the activity class that invokes the style file, add the following code:

Java code

Set the mini ad background color    
appconnect.getinstance (this). Setadbackcolor (Color.argb ();  
   
Set up the mini AD advertising language color    
appconnect.getinstance (this). Setadforecolor (Color.yellow);  
   
If the above two colors are not set, then the default is black background white    
linearlayout minilayout = (linearlayout) Findviewbyid (r.id.miniadlinearlayout);  
   
New Miniadview (this, minilayout). Displayad (10); Default 10 seconds to switch ads 

6. Add the application list

Application list (integral wall) is the main source of revenue, higher than advertising revenue, a single download price is generally 0.5 yuan, very impressive,

1) activtiy, click event Add

Appconnect.getinstance (This). Showoffers (this);

In order to better let the recommended application download, is generally combined with points, such as a look at the map software, if you want to see the map, the results are not enough, there is no way only download applications to obtain points.

Step 1: Get the user points/virtual currency balances from the server side:

Appconnect.getinstance (This). Getpoints (this);

Step 2: Ensure that the Updatepointsnotifier interface is implemented in the This class, implementing the following two methods for the results returned by the receiving server asynchronously:

public void Getupdatepoints (String currencyname, int pointtotal);/Get success

public void getupdatepointsfailed (String error);//Get failed

2 Cost user Virtual currency

To spend (deduct) a user's virtual currency interface:

Appconnect.getinstance (This). spendpoints (int amount, this);

The response result of the call to this method is returned via the Updatepointsnotifier interface implemented in this

3 Reward user Virtual currency

To grant (increase) the user's virtual currency interface:
Appconnect.getinstance (This). awardpoints (int amount, this);
The response result of calling this method will be returned through the Updatepointsnotifier interface implemented in this.

Note that all virtual currencies obtained through Wanpo ads are automatically given to the user without invoking the interface. This interface is only used for additional user virtual currency when the user completes other tasks specified by the developer. Open to disable the interface through admin background.

This completes the process of inserting ads into Android apps.

Thank you for reading, I hope to help you, thank you for your support for this site!

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.