用户工具

站点工具


差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

en:razor:android-developer-guide [2015/09/15 10:36]
cobub
en:razor:android-developer-guide [2017/07/14 11:18]
行 1: 行 1:
-~~Title:​Cobub Razor Android Developer Guide - Mobile Apps Marketing Platform of Open Source - Mobile Analytics & Mobile Push Notification Solutions - Cobub Mobile Developer Center~~ 
-{{description>​Cobub Razor is an Open Source Mobile Analytics. The goal of this document is to explain usage rules of Cobub Razor Android ​ SDK for facilitating developers.}} 
-{{keywords>​Cobub Razor,open source mobile analytics,​mobile analytics,​mobile app analytics, android, developer guide, setup, configuration}} 
  
-====== Cobub Razor Android Developer Guide ====== 
- 
-===== 1   ​Overview ===== 
- 
-==== 1.1   ​Documentation Goal ==== 
- 
-The goal of this document is to explain usage rules of Cobub Razor Android ​ SDK for facilitating developers. 
- 
-==== 1.2   ​Application Scope ==== 
- 
- 
-This document is for Android ​ SDK developers, who use the Open Source Mobile Analytics – Cobub Razor. 
- 
-==== 1.3   Terms and Abbreviations ==== 
- 
- 
-Cobub Razor  -  [[en:​start|The Open Source ​ Mobile Analytics]] 
- 
-===== 2   Basic Setup Guide ===== 
- 
- 
-==== 2.1   ​Register App,Obtain AppKey,Download Developer Documentation ==== 
- 
- 
-First please setup the Web Server of Cobub Razor ([[en:​razor:​installation|instruction]]), ​ then register App on web server and fill App info after login. ​ Once App is created successfully,​ you could obtain AppKey. 
- 
-==== 2.2   SDK Usage Step ==== 
- 
- 
-=== 2.2.1   ​Import sdk jar === 
- 
-Open android_sdk in the directory you uploaded on the server. ​ Import android_sdk to Eclipse and export sdk jar file.  
- 
-Eclipse users right click own project root directory and select Properties —>Java Build Path —>​libraries. Then click Add External JARs and select path of com.wbkit1.0.jar. Finally, click OK and then import is completed. 
- 
-=== 2.2.2   ​Configure AndroidManifest.xml === 
- 
-    * Add App **AppKey** (mandatory) 
-Add AppKey obtained by App to meta-data of AndroidManifest.xml. 
- 
-(Note: String must be ‘UMS_APPKEY‘) 
- 
-    * Add permission **android.permission.INTERNET** (mandatory) 
-Send user analytic data to server. 
- 
-    * Add permission **android.permission.READ_PHONE_STATE** (mandatory) 
-Obtain relevant status info of phone. 
- 
-    * Add permission **android.permission.ACCESS_FINE_LOCATION** (mandatory) 
-Obtain current user’s location info. 
- 
-    * Add permission **android.permission.ACCESS_WIFI_STATE** (mandatory) 
-Visit Wi-Fi network status info. 
- 
-    * Add permission **android.permission.GET_TASKS** (mandatory) 
-Obtain recent running task info. 
- 
-    * Add permission **android.permission.WRITE_EXTERNAL_STORAGE** (mandatory) 
-Read and write file to sdcard. 
- 
-    * Add permission **android.permission.READ_LOGS**(mandatory) 
-Read program error log. 
- 
-    * Add permission **android.permission.ACCESS_NETWORK_STATE**(mandatory) 
-Visit GSM network info. 
- 
-The AndroidManifest.xml file as shown below: 
- 
-<​code><​manifest xmlns:​android="​http://​schemas.android.com/​apk/​res/​android" ​ 
-   
-package="​com.wbtech.test_sample"​   
-android:​versionCode="​1"​   
-android:​versionName="​1.0"​ >   
-<​uses-sdk   
-android:​minSdkVersion="​8"​   
-android:​targetSdkVersion="​15"​ />   
-<​uses-permission android:​name="​android.permission.INTERNET"/>​   
-<​uses-permission android:​name="​android.permission.WRITE_EXTERNAL_STORAGE"/>​   
-<​uses-permission android:​name="​android.permission.READ_PHONE_STATE"/>​   
-<​uses-permission android:​name="​android.permission.ACCESS_FINE_LOCATION"/>​   
-<​uses-permission android:​name="​android.permission.ACCESS_WIFI_STATE"/>​   
-<​uses-permission android:​name="​android.permission.GET_TASKS"/>​   
-<​uses-permission android:​name="​android.permission.READ_LOGS"/>​   
-<​uses-permission android:​name="​android.permission.ACCESS_NETWORK_STATE"/>​   
-<​application   
-android:​icon="​@drawable/​ic_launcher"​   
-android:​label="​@string/​app_name"​   
-android:​theme="​@style/​AppTheme"​ >   
-<​activity   
-android:​name="​.MainActivity"​   
-android:​label="​@string/​title_activity_main"​ >   
-<​intent-filter>​   
-<action android:​name="​android.intent.action.MAIN"​ />   
-<​category android:​name="​android.intent.category.LAUNCHER"​ />   
-</​intent-filter>​   
-</​activity>​   
-<​meta-data android:​name="​UMS_APPKEY"​ android:​value="​bb08202a625c2b5cae5e2632f604352f "/>   
-</​application>​   
-</​manifest></​code>​ 
- 
-=== 2.2.3   Add Code === 
-* Add Reference 
-        import com.wbtech.ums.UmsAgent;​ 
-* Init  
-        Call UmsAgent.init(Context context, String url)in onCreate() method of App enter Activity, make sure that this method be called before other methods. The url parameter should be ended with "​index.php?",​ like "​http://​demo.cobub.com/​razor/​index.php?"​. 
-* Obtain UserID 
-        Call UmsAgent.bindUserid(Context context, String userID) method where you can obtain the unique identifier of user,   and this method will record the userID on behalf of the user of using this application. 
-* Bind Tags 
-        Call UmsAgent.postTags(final Context context, final String tags) method where you can obtain the attributes to tag the user. The tag values will be sent to server. 
-* Register Activity 
-        Call UmsAgent.onResume(Context) in onResume method of every Activity. The passed parameter is the reference of current context. This method will read AppKey from AndroidManifest.xml automatically and record the time of user enters into this activity. Do not pass global application context. ​ 
- 
-<​code>​protect void onResume(){ 
-   ​super.onResume();​ 
-   ​UmsAgent.onResume(this);​ 
-}</​code>​ 
- 
-Call UmsAgent.onPause(Context) in onPause method of every Activity. Parameter is the reference of current context. This method will record the time of user leaves this activity. 
- 
-<​code>​protected void onPause(){ 
-   ​super.onPause();​ 
-   ​UmsAgent.onPause(this);​ 
-}</​code>​ 
-Call UmsAgent.postClientData(Context) ​ in onCreate method of every Activity. Parameter is the reference of current context. 
- 
-<​code>​public void onCreate (Bundle savedInstanceState){ 
-   ​super.onCreata(savedInstanceState);​ 
-   ​setContentView(R.layout.main);​ 
-   ​UmsAgent.postClinetData(this);​ 
-}</​code>​ 
-Code sample as shown below: 
- 
-<​code>​public void onCreate(Bundle savedInstanceState) { 
-    super.onCreate(savedInstanceState);​ 
-    setContentView(R.layout.activity_main);​ 
-    button = (Button) findViewById(R.id.button1);​ 
-    UmsAgent.init(this."​http://​demo.cobub.com/​razor/​index.php?"​);​ 
-    UmsAgent.update(this);​ 
-    UmsAgent.setDefaultReportPolicy(this,​ SendPolicy.REALTIME);​ 
-    UmsAgent.bindUserid(this,​ "​cobub.open@gmail.com"​);​ 
-    button.setOnClickListener(new OnClickListener() { 
- 
-       ​@Override 
-       ​public void onClick(View v) { 
-          // TODO Auto-generated method stub 
-          UmsAgent.onEvent(MainActivity.this,​ "​eventid"​);​ 
-          UmsAgent.onEvent(MainActivity.this,​ "​event_id",​ "​label",​ 30.0); 
-       } 
-    }); 
- 
-}</​code>​ 
- 
-=== 2.2.4   ​Integration Instructions === 
- 
-We recommend you call **UmsAgent.onResume()** and **UmsAgent.onPause()** in all activities. ​ If not,  Page View report and some related reports will not be available on the Web Server. 
- 
-=== 2.2.5   Note === 
-    * AppKey 
-Check to make sure that AppKey has been correctly written to Androidmanifest.xml. 
-    * Permission 
-Check to make sure that all required permissions have been added. 
-    * Use API 
-Check to make sure that all Activities have called onResume and onPause. 
-    * Check Network 
-Check to make sure that test phone or simulator has successfully connected to network. 
- 
-===== 3   ​Advanced Setup Guide ===== 
- 
-==== 3.1   Error Report ==== 
- 
-Android SDK could help you catch exit exception during App usage and send error report to server. Error report includes App version, OS version, device type and stacktrace of program exception. These data will help you debug App errors. We provide two ways to report error info. One is catched automatically by system and another is passed by developers. 
- 
- 
-For the former, you need to add android.permission.READ_LOGS permission in AndroidManifest.xml and call UmsAgent.onError(Context) in onCreate of Main Activity(App entry). 
-<​code>​public void onCreate(Bundle savedInstanceState) { 
-    super.onCreate(savedInstanceState);​ 
-    setContentView(R.layout.activity_main);​ 
-    UmsAgent.onError(this);​ 
-} 
-</​code>​ 
-<​code>​public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);​ setContentView(R.layout.activity_main);​ UmsAgent.onError(this);​ } </​code>​ 
- 
-For the latter,​developers need to call UmsAgent.onError(Context,​String)and pass error info catched by their own to the second parameter. You can check that the log has been sent to the error analytics data statistics reports of my product. 
- 
-==== 3.2   ​Custom Event ==== 
- 
-Except basic data statistics analysis, the SDK also support analysis of custom event. For example, you could count ad clicks or times of  video has been played. Here we provide several simple and common interfaces: 
- 
- 
-UmsAgent.onEvent(Context context,​String event_id); 
- 
-//context: the reference of current context 
- 
-event_id: the ID of current statistics event, could not have spaces.// 
- 
-Invoke this API will send event info to the server and generate the event report on the server which analyzes sending times and changing trends corresponding to event_id, such as AD clicks, message numbers and so on. For example, to monitor AD clicks of App in MainActivtiy. Event ID is “ ad_click“. Once AD is clicked, you need call 
- 
- 
-UmsAgent.onEvent(MainActivity.this,​“ad_click“) 
- 
-in App to notify server that an AD click event  has occurred. 
- 
-UmsAgent.onEvent(Context context,​String event_id,​int acc) 
- 
-For the frequent events, you can maintain a counter for them . In this way, event that are triggered by many times will  just need generate one message. This message includes triggered times of this event. Here is overloaded two APIs: 
- 
-UmsAgent.onEvent(Context context,​String event_id,​int acc) 
-UmsAgent.onEvent(Context context,​String event_id,​String label,int acc) 
- 
-**acc :** triggered times of corresponding event. In addition to the statistics of the number of events, here we  can save and statistics the value of the label according to event_id.The overloaded methods are as follows: 
- 
- 
-UmsAgent.onEvent(Context context,​String event_id,​String label,​double value) 
- 
-For example, event_id represents an “ order “ event, then the label can be marked as an " order number ", and the value represents the value of  the" order number ". 
- 
- 
-==== 3.3 Debug ==== 
- 
-Cobub Android SDK provides the Debug function, which can help developers to locate problems. Developers can enable debug function and set the different log level: 
-<code java> 
-UmsAgent.setDebugEnabled(true);​ 
-UmsAgent.setDebugLevel(UmsAgent.LogLevel);​ 
-</​code> ​ 
-LogLevel has five levels:​Info,​ Debug, Warn, Error, Verbose. 
- 
-===== 4   App Update ===== 
-==== 4.1   ​Upload APK ==== 
- 
-This function will help you push your new version App to users. You just need to modify VersionCode in AndroidManifest.xml and upload App APK to server. 
- 
-==== 4.2   Add Permission ==== 
- 
-android.permission.WRITE_EXTERNAL_STORAGE 
-==== 4.3   Basic Function ==== 
- 
-Call UmsAgent.update(this) in onCreate() of App entry Activity when you want the APP to check that whether Web Server has a new version of the App automatically. 
- 
-<​code>​public void onCreate(Bundle savedInstanceState) { 
-super.onCreate(savedInstanceState);​ 
-setContentView(R.layout.activity_main);​ 
-UmsAgent.update(this);​ 
-}</​code>​ 
- 
-In consideration of limitations of the user traffic, we now do automatic reminders under Wi-Fi intervention by default. 
- 
-==== 4.4   ​Mechanism Instructions ==== 
- 
-When updating App every time, you just need to modify VersionCode and upload App APK to server. 
- 
-**UmsAgent.update()** will check that whether there is a new version App on server. It will notify user whether to ungrade SDK if there is a new App SDK. SDK wil upgrade after user choose to ungrade. (whether to ungrade according to version code) 
- 
-===== 5   Data Sending ===== 
-5.1   Model Explaination 
- 
-    * Start sending(recommended) 
- 
-App only sends a message to server when it starts. All messages produced during App will be sent to server on next time start. If the App starts without network, then the messages will be stored in local and App will try to send next time. 
- 
-    * Real-time Sending 
-Once App produces a message, sending it to server immediately. 
- 
-5.2   Set sending model 
- 
-Call UmsAgent.setDefaultReportPolicy(Context,​int) in entry Activity. Parameter int could be 0 or 1. 
- 
-1 stands for Real-time sending and 0 stands for Start sending. 
- 
-===== 6   ​Online Configuration ===== 
- 
-UmsAgent.updateOnlineConfig(Context) 
- 
-Invoke this API in **onCreate()** method of App's entey Activity and SDK will get your online configuration on the server and store this info in local. 
- 
-You can also read your custom parameters by using following API: 
- 
-UmsAgent.updateOnlineConfig(Context context,​String key) 
- 
-**key:** the key which has been defined on the web . A empty string will be returned if the corresponding value is not read. 
en/razor/android-developer-guide.txt · 最后更改: 2017/07/14 11:18 (外部编辑)