Source Access to Github:https://github.com/drjia/androidlogcollector
has been made into the form of the SDK, the source code has been open, the source can not understand the please google itself.
If you want to customize the SDK to suit your app, fork it yourself.
Androidlogcollectorandroid app crash Log Collection SDK 1.0
Dr. Jia
Crash Log Collection method:
1.LogCollector is a Lib package that is imported in a project that needs to add the crash Log SDK.
2. After you import lib, add permissions to your project's Androidmanifest.xml file:
<uses-permission android:name=" Android.permission.READ_PHONE_STATE "/> <use S-permission android:name= "Android.permission.INTERNET"/> <uses-permission android:name= "android.permission . Write_external_storage "/> <uses-permission android:name=" Android.permission.ACCESS_NETWORK_STATE "/> <uses-permission android:name= "Android.permission.ACCESS_WIFI_STATE"/>
3. Rewrite your application in your own project and add in OnCreate
LogCollector.init(getApplicationContext(), UPLOAD_URL, params);
PS: Rewrite your application remember to register in manifest
Parameters:
1.Context
2.String upload_url, upload address URL, support HTTP and HTTPS mode, POST method.
3.HttpParameters params, custom class, for post upload other parameters.
Description
After a crash, the logs are saved in the/data/data/{your package name}/files/directory
Log only one file, multiple data logs saved
Log file upload will be automatically deleted after the upload is unsuccessful, do not delete
Log format can be changed according to your own needs in the source code
HTTP post-transmitted data can also be modified by itself
Reference code:
public class MyApplication extends application {//post method, upload logfile Url,replace your site. Support HTT P or HTTPS private static final String Upload_url = "http://xxxxxxxx"; @Override public void OnCreate () {super.oncreate (); Upload logfile, post params. Httpparameters params = new httpparameters (); Params.add ("Key1", "value1"); Params.add ("Key2", "value2"); Params.add ("Key3", "value3"); ......//replace your key and value; Boolean isdebug = true; Set debug mode, you can see the debug log, and also you can get the logfile in SDcard; Logcollector.setdebugmode (Isdebug); Logcollector.init (Getapplicationcontext (), upload_url, params);//params can be null}}
Upload Log method:
Init must be executed in application first,
Then add the following code at any location:
LogCollector.upload(boolean isWifiOnly);
Parameters:
1.boolean iswifionly; True means send only in the case of WiFi, false means send with network (including traffic and WiFi)
You can trigger at the right time in the service,activity and so on, no card interface will affect performance.
Reference code:
private void uploadLogFile(){ boolean isWifiOnly = true;//only wifi mode can upload LogCollector.upload(isWifiOnly);//upload at the right time }
Debugging:
Called Prior to Init
LogCollector.setDebugMode(boolean isDebug);
Description
1. You can see the log information of the stack after you turn on debugging
2. The saved crash log can be viewed in the Android/data/{your package name}/log/directory under the SD card.
The logs in this directory will not be deleted automatically, please clear them in time, avoid taking up space