Reprint please indicate the source: a column of Maple Leaf
In the previous article, we introduced the hot fixes in the Android community, and introduced several popular heat repair frameworks, as well as their pros and cons, and introduced the practice of thermal remediation in their own projects. At present, the main principle of heat repair is actually divided into two, one is through the use of DEX load order to achieve thermal repair function, one is through the native layer to achieve the replacement of the pointer to achieve thermal repair function, the two advantages and disadvantages can be based on the needs of their products to choose different solutions.
and the text will introduce another basic feature of Android products-data statistics. The significance of the app data statistics is that through the statistical user's behavior in a targeted update display algorithm, according to the user's behavior habits of new product features and so on, specifically, when we develop a good app will send it to the application market, but there are many application market (such as Pea pod, app Bao, Android Market, etc.), So the question is, if we want to count the number of downloads we've developed, we have to use statistics, and not only can we count the number of downloads and launches of our app, we can also count the amount of pages visited, the bugs in the program, and so on, because there's a continuous iteration and user experience for the project, Therefore, it is an essential task to do data statistic work well.
The data statistics in this paper mainly introduce two kinds: third-party statistic service and self-realization data statistic function.
Relatively these two ways each have advantages and disadvantages, third-party statistical services are simple, convenient, wide range of statistics, but the data are stored in a third party, for some data sensitive app may not like this way, and their own realization of the main advantages of data statistics function is security can be customized, of course, the shortcomings are obvious, is cumbersome Complex.
Let me make a brief introduction to these two data statistics separately.
- Third-party statistical services
In general, the app is the use of third-party data statistics services, friends of the League, Baidu statistics, and so on, here is a brief introduction of Friends league statistics, the rest are similar.
Friends League Statistics Official website
Friends of the league statistics are not only statistical related functions, but also provides error analysis, social sharing, push, instant communication, and so on, of course, here we focus on the analysis of its data statistics function.
In the Friends League official website we can see its introduction to the statistical services, here we probably look at:
We can find that we provide user statistics, channel statistics, page access path statistics, click event Statistics, and so on.
So how can we inherit the statistical function of the Friend League, which has been described in detail in the SDK documentation, the approximate integration process is to download the Friend Alliance SDK Jar package, then reference, and invoke the relevant API in the corresponding Activity/fragment life cycle method.
- Self-Realization Data statistics function
For some data-sensitive apps may be able to implement some of their own data statistics function is a good choice, the original I have done similar functions, the principle is to refer to friends of the data statistics in the app when the application is opened to perform data escalation function.
Here is a brief introduction to the flow of data statistics that you have implemented:
(1) Data statistics reporting is divided into two main methods, network request escalation and file information escalation;
(2) Network request escalation is a direct call to the network request if the request fails, the escalation information is saved to a local file;
(3) Local escalation file set the threshold and interval time, if the distance from the last escalation time is greater than the threshold or the file size is greater than the threshold to perform escalation operations, if the escalation is successful, delete the local data file;
(4) Local data files are encrypted and compressed before being escalated;
(5) When the app is opened to perform a data escalation operation, under the specific operation can be carried out escalation operations;
(6) The escalation operation is performed in service services, and the escalation operation is prevented from being interrupted by the process being killed;
Finally, the data statistics services that are customized to achieve data escalation are posted:
/** * Created by Aaron on 2016/4/8. * Desc:uu Dot Service */ Public class uupointservice extends Service { @Override Public void onCreate() {Super. OnCreate (); }@Override Public int Onstartcommand(Intent Intent,intFlagsintStartid) {/** * desc: The service for the app dot service * Mainly implement two background services: * (1) memory data escalation; * (2) file data escalation; */ if(Intent! =NULL&& Intent.getstringextra (uupoint.loadtype)! =NULL&& Intent.getstringextra (Uupoint.loadtype). Trim (). Equals (Uupoint.loaddata)) {if(UUPoint.writeMap.size () >0) {//(1) Convert data FinalList<string> strlist =NewArraylist<string> (); iterator<map.entry<string, integer>> Iterator = UUPoint.writeMap.entrySet (). Iterator (); while(Iterator.hasnext ()) {StringBuffer SB =NewStringBuffer (); map.entry<string, integer> Entry = Iterator.next (); String key = Entry.getkey (); Integer count = Entry.getvalue (); Sb.append (Key). Append (","). Append (count); Strlist.add (Sb.tostring ()); }if(Strlist.size () >0) {//Upload server data upload server dataSystemCommon.ReportLogBatch.Builder Builder = SystemCommon.ReportLogBatch.newBuilder (); Builder.addalllogline (strlist); SystemInterface.ReportLogInfoRequest.Builder request = SystemInterface.ReportLogInfoRequest.newBuilder (); Request.setlogdata (Bytestring.copyfrom (Gziputils.compress (Builder.build (). Tobytearray ()));//Compressed data packetsNetworktask task =NewNetworktask (CmdCodeDef.CmdCode.ReportLogInfo_VALUE); Task.setbusidata (Request.build (). Tobytearray ()); Networkutils.executenetwork (Task,NewHttpresponse.networkresponse<uuresponsedata> () {@Override Public void Onsuccessresponse(Uuresponsedata responsedata) {if(Responsedata.getret () = =0) {Try{Systeminterface.reportloginforesponse response = Systeminterface.reportloginforespons E.parsefrom (Responsedata.getbusidata ());if(Response.getret () = =0) {/*mlog.i ("tab", "########################"); for (String str:strlist) {mlog.i ("tab", str); }*/UUPoint.writeMap.clear (); Uupointutils.setlastpointtime (Uupointservice. This);/*mlog.i ("tab", "Report data Completion ################"); */}Else{Uupoint.savewritetoio (Uupointservice). This);//Persist data in the write map to io} }Catch(Exception e) {Uupoint.savewritetoio (Uupointservice). This);//Persist data in the write map to io} }Else{Uupoint.savewritetoio (Uupointservice). This);//Persist data in the write map to io} }@Override Public void OnError(Volleyerror errorresponse) {MLOG.I ("tab","Save to local file"); Uupoint.savewritetoio (Uupointservice. This); }@Override Public void Networkfinish() { } }); } } }//Upload files Else if(Intent! =NULL&& Intent.getstringextra (uupoint.loadtype)! =NULL&& Intent.getstringextra (Uupoint.loadtype). Trim (). Equals (Uupoint.loadfile)) {File File =NewFile (Config.countfile); list<file> fileList = arrays.aslist (File.listfiles ());if(FileList! =NULL&& filelist.size () >0) {//Sort by file nameCollections.sort (FileList,NewComparator<file> () {@Override Public int Compare(File lhs, file RHS) {returnRhs.getname (). CompareTo (Lhs.getname ()); } });//Upload files for(FinalFile files:filelist) {//Decrypt first, in use note encryptionFileencrypter.decrypt (Files, uupoint.secretkey);//Decryption if(Config.isnetworkconnected (Uupointservice. This) {Networktask Networktask =NewNetworktask (CmdCodeDef.CmdCode.ReportLogFile_VALUE); Networktask.setuploaddatafile (true);//Upload large point data fileNetworktask.setbusidata (Uupointutils.getbytesfromfile (files)); Networkutils.executenetwork (Networktask,NewHttpresponse.networkresponse<uuresponsedata> () {@Override Public void Onsuccessresponse(Uuresponsedata responsedata) {if(Responsedata.getret () = =0) {Try{Systeminterface.reportloginforesponse response = Systeminterface.reportloginfores Ponse.parsefrom (Responsedata.getbusidata ());if(Response.getret () = =0) {//Upload successful, delete encrypted filesFiles.delete (); MLOG.I ("tab","Upload file complete"+ files.getname () +"######################"); }Else{Fileencrypter.encrypt (files, uupoint.secretkey);//upload failed, re-encrypt file} }Catch(Exception e) {E.printstacktrace (); Fileencrypter.encrypt (Files, uupoint.secretkey);//upload failed, re-encrypt file} }Else{Fileencrypter.encrypt (files, uupoint.secretkey);//upload failed, re-encrypt file} }@Override Public void OnError(Volleyerror errorresponse) {MLOG.I ("tab", errorresponse.tostring ()); Fileencrypter.encrypt (Files, uupoint.secretkey);//upload failed, re-encrypt file}@Override Public void Networkfinish() { } }); } } } }return Super. Onstartcommand (Intent, flags, Startid); }@Override Public void OnDestroy() {Super. OnDestroy (); }@Override PublicIBinderOnbind(Intent Intent) {return NULL; }}
Summary:
In general, the direct use of third-party statistical services can already meet the vast majority of business needs, of course, if the data is more sensitive, you can also implement the data Reporting statistics function.
In addition to product development technology, skills, practice interested students can refer to my:
Android Product Development (i) –> Practical development Code
Android product Development (ii) –> start Page optimization
Android Product Development (iii) –> base class activity
Android product Development (iv) –> reduce APK size
Android Product Development (v) –> multi-channel packaging
Android product Development (vi) –>APK confusion
Android Product Development (vii) –>APK hot fix
This article synchronizes to GitHub: Https://github.com/yipianfengye/androidProject, Welcome to star and follow
Android product Development (eight)-->app data statistics