Recently, some netizens sent a private message to me asking me how to use the points function in applications to get some extra income, the following describes how to use credits to obtain income in the application using the credit model of the wanpu advertising platform (the wanpu SDK also has development documents, but the first time I access the credit model, it may be difficult to use it, so let me talk about the specific steps ).
First, let's talk about the advertisement of wanpu. The content of a previous blog has introduced this advertisement platform. In general, it is a very good advertising platform for individual developers, recently I have been using, recommended to everyone, web site: http://www.waps.cn /? F = wind7rui
My Sina Weibo (wind Swiss): http://weibo.com/tianrui1990
Okay, let's get started!
Step 1: Download the universal advertising SDK and import appoffer_1.6.3.jar to the project where you want to embed the advertisement.
Step 2: Modify the androidmanifest. xml file.
Add the following permissions to the androidmanifest. xml file and add them outside the <Application> segment. The Code is as follows:
<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. permi Ssion. get_tasks "/> <! -- The following two permissions are optional to support special ad formats --> <uses-Permission Android: Name = "com. android. launcher. permission. install_shortcut "/> <uses-Permission Android: Name =" com. android. browser. permission. write_history_bookmarks "/>
Then, add the following registration content in the <Application> section. The Code is as follows:
<Activity Android: Name = "com. WAPs. offerswebview" Android: configchanges = "keyboardhidden | orientation"/> <! -- The following attribute is the Application ID, which is obtained from the background of wanpu --> <meta-data Android: Name = "waps_id" Android: value = "Application ID"/> <! -- The following attributes are distribution channel IDs. For the encoding table, see the appendix at the end of this document --> <meta-data Android: Name = "waps_pid" Android: value = "Distribution Channel ID"/>
Note: 1. here you need to modify
<Meta-data Android: Name = "waps_id" Android: value = "Application ID"/>
In the "Application label" changed to you in the universal platform to add the application automatically generated after the value (first to the universal registration, and then add the application), URL: http://www.waps.cn /? F = wind7rui
2. Set
<Meta-data Android: Name = "waps_pid" Android: value = "Distribution Channel ID"/>
The "Distribution Channel ID" in is changed to the channel ID of the application market to be uploaded. These channel IDs are already specified. They are available in the Development SDK of wanpu. Check them carefully. Be sure: fill in "WAPs" for the version uploaded to the hichina platform, and fill in the corresponding value (for example, "Google") for the version distributed to other channels, and then repackage it; different distribution packages should be marked with different channels to distinguish data from different channels on the hichina statistics platform ..
Step 3: add the data interface code.
Note: This part of code must be added, which is the key for the application to obtain data.
This interface is the basis for the normal use of all other interfaces. You must call this interface each time an application starts to obtain accurate statistics.
.
In this example, there are two interfaces. The first interface is the main interface. There are two buttons in total. Click the "click" button. If your points exceed 50, the page will jump to the points page. Otherwise, the page will not jump, insufficient credits are prompted. :
The activity on the main interface is mainactivity. mainactivity must implement the updatepointsnotifier interface and implement the getupdatepoints (string currencyname, intpointtotal) and getupdatepointsfailed (string error) methods. The getupdatepoints (string currencyname, intpointtotal) method is used to successfully obtain points. getupdatepointsfailed (string
Error) method is used to obtain the points failed. Appconnect. getinstance (this). getpoints (this) is added to the onresume () method of mainactivity to obtain the user point/virtual currency balance from the server. Add the ondestroy () method to mainactivityAppconnect. getinstance (this). Finalize ()Used to release the system resources occupied by the SDK.
The mainactivity code is as follows:
Package COM. android. jifen; import COM. WAPs. appconnect; import COM. WAPs. updatepointsnotifier; import android. app. activity; import android. content. intent; import android. OS. bundle; import android. view. view; import android. view. view. onclicklistener; import android. widget. button; import android. widget. toast; public class mainactivity extends activity implements updatepointsnotifier {/** called when the activity is first created. */private button BTN, exit; private string currentname; // Save the name of the current point private int point; // Save the current number of points @ overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); // method ①: Read waps_id and waps_pidappconnect.getinstance (this) through the androidmanifest file; // ensure that waps_idbtn = (button) findviewbyid (R. id. BTN); exit = (button) findviewbyid (R. id. exit); BTN. setonclicklistener (New onclicklistener () {@ overridepublic void onclick (view v) {// todo auto-generated method stubif (point> = 50) {intent = new intent (); intent. setclass (getapplicationcontext (), jifenactivity. class); startactivity (intent);} else {toast. maketext (getapplicationcontext (), "Your points are insufficient", toast. length_short ). show () ;}}); exit. setonclicklistener (New onclicklistener () {@ overridepublic void onclick (view v) {// todo auto-generated method stubfinish (); system. exit (0) ;}}) ;}@ overrideprotected void ondestroy () {// todo auto-generated method stubappconnect. getinstance (this ). finalize (); super. ondestroy () ;}@ overrideprotected void onresume () {// todo auto-generated method stub // obtain the virtual currency of the current user from the server. // return the result in the callback function getupdatepoints (...) appconnect. getinstance (this ). getpoints (this); super. onresume () ;}@ overridepublic void getupdatepoints (string arg0, int arg1) {// todo auto-generated method stubthis. currentname = arg0; this. point = arg1 ;}@ overridepublic void getupdatepointsfailed (string arg0) {// todo auto-generated method stub }}
Note: All virtual currency obtained through the universal advertisement will be automatically given to the user.
In the same way, use the virtual currency interface of the user (deduct), which is appconnect. getinstance (this ). spendpoints (INT amount, this) calls the response result of this method will be returned through the updatepointsnotifier interface implemented in the current activity; the interface for granting (adding) User Virtual currency is appconnect. getinstance (this ). awardpoints (INT amount, this) calls the response result of this method will be returned through the updatepointsnotifier interface implemented in the current activity, no manual operation is required.
The androidmanifest. xml file code is attached as follows:
<? XML version = "1.0" encoding = "UTF-8"?> <Manifest xmlns: Android = "http://schemas.android.com/apk/res/android" package = "com. android. jifen "Android: versioncode =" 1 "Android: versionname =" 1.0 "> <uses-SDK Android: minsdkversion =" 7 "/> <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 special ad formats --> <uses-Permission Android: Name = "com. android. launcher. permission. install_shortcut "/> <uses-Permission Android: Name =" com. android. browser. permission. write_history_bookmarks "/> <application Android: icon =" @ drawable/icon "Android: Label =" @ string/app_name "> <activity Android: Name = ". mainactivity "Android: Label =" @ string/app_name "> <intent-filter> <action Android: Name =" android. intent. Action. main "/> <category Android: Name =" android. intent. category. launcher "/> </intent-filter> </activity> <activity Android: Name =" jifenactivity "/> <activity Android: Name =" com. WAPs. offerswebview "Android: configchanges =" keyboardhidden | orientation "/> <! -- The following attribute is the Application ID, which is obtained from the background of wanpu --> <meta-data Android: Name = "waps_id" Android: value = ""/> <! -- The following attributes are the distribution channel ID. For the encoding table, see the appendix at the end of this document --> <meta-data Android: Name = "waps_pid" Android: value = "WAPs"/> </Application> </manifest>
This is a simple point function.
If you do not understand the place can go to my Sina Weibo private letter I, my Sina Weibo: http://weibo.com/tianrui1990
Http://www.waps.cn /? F = wind7rui