Examples of inserting advertisements in Android Applications
As we all know, Android applications in China are basically free, so how do developers get income? Inserting advertising into applications is a commonly used means of profit. This article explains how to insert advertisements in Android applications.
There are many advertising platforms in China. Wanpu, youmi and duopu have a large number of users. I won't introduce them one by one to avoid saying that I advertise. This paper takes Wanpu as an example.
1. First, go to the official website of Wanpu to download the SDK and import the jar package in the SDK into the Lib directory of the project.
2. Modify androidmanifest XML file.
Ensure that the application has the following permissions:
XML / HTML code
Add the following in the < Application > section:
XML / HTML code
3. Interface code
(1) Data statistics interface
This interface is the basis for the normal use of all other interfaces. This interface must be called every time the application starts to ensure accurate statistical data.
Step 1: add the following line of code to the first activity class (the first class started) in the application:
Java code
Step 2: in the processing method of program exit, add the following line of code:
Java code
4. Add banner
Add to layout file:
XML / HTML code
Add the following code to the activity:
Java code
5. Mini Banner add
Step 1: copy the following code into the layout file of the corresponding Activiy and place it in the appropriate location:
XML / HTML code
Step 2: in the activity class calling the style file, add the following code:
Java code
6. Application list add
Application list (integral wall) is the main source of revenue, which is higher than advertising revenue. The price of a single download is generally 0.5 yuan, which is considerable,
1) Activate and click add event
AppConnect. getInstance(this). showOffers(this);
In order to better let the recommended application download, it is generally combined with points, such as a picture viewing software. If you want to see the picture, the points are not enough. There is no way to only download the application to obtain points.
Step 1: obtain user points / virtual currency balance from the server:
AppConnect. getInstance(this). getPoints(this);
Step 2: ensure that the updatepointsnotifier interface is implemented in this class, and the following two methods are implemented to asynchronously receive the results returned by the server:
public void getUpdatePoints(String currencyName,int pointTotal);// Successfully obtained public void getupdatepointsfailed (string error)// Acquisition failed
2) Spend user virtual currency
Virtual currency interface of expense (deduction) user:
AppConnect. getInstance(this). spendPoints(int amount, this);
The response result of calling this method will be returned through the updatepointsnotifier interface implemented in this
3) Reward users with virtual currency
Interface for granting (adding) user virtual currency:
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 Wanpu advertising will be automatically given to users without calling the interface. This interface is only used to give the user additional virtual currency if the user has completed other tasks specified by the developer. On, you can disable the interface through the management background.
This basically completes the process of inserting advertisements in Android applications.