Collect client error messages

Source: Internet
Author: User
public class CrashApplication extends Application {@Overridepublic void onCreate() {super.onCreate();MyUncaughtExceptionHandler handler = MyUncaughtExceptionHandler.getInstance();handler.init(getApplicationContext());Thread.currentThread().setUncaughtExceptionHandler(handler);}}
Public class implements uncaughtexceptionhandler {Private Static implements handler; private context; private implements () {} public static synchronized myuncaughtexceptionhandler getinstance () {If (handler = NULL) {handler = new myuncaughtexceptionhandler (); Return handler;} else {return handler ;}} public void Init (context) {th Is. Context = context ;}@ overridepublic void uncaughtexception (thread, throwable ex) {try {system. Out. println ("an error occurred! "); Stringbuilder sb = new stringbuilder (); // obtain the version packagemanager = context. getpackagemanager (); packageinfo = packagemanager. getpackageinfo (context. getpackagename (), 0); string versionname = packageinfo. versionname; sb. append ("program version:" + versionname ). append ("\ n"); // obtain the device information field [] fields = build. class. getdeclaredfields (); For (INT I = 0; I <fields. length; I ++) {fields [I]. setaccessible (true); string name = Fields [I]. getname (); string value = Fields [I]. get (null ). tostring (); sb. append (name + "=" + value ). append ("\ n") ;}// get error message stringwriter wR = new stringwriter (); printwriter err = new printwriter (WR); Ex. printstacktrace (ERR); string MSG = Wr. tostring (); sb. append (MSG); system. out. println (sb. tostring (); // upload server (not implemented)} catch (exception e) {e. printstacktrace ();} // process suicide android. OS. process. killprocess (Android. OS. process. mypid ());}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.