VIGNESH VIGNESH - 1 year ago 82
Android Question

Getting the crash log and send it as email

From my search, i got the below code for getting the Crash Log .

try {
Process process = Runtime.getRuntime().exec("logcat -d");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));

StringBuilder log=new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null)

But where do i add this code, so that i should get the crash report whenever my app crashes .

Also i want to email it or send to the server, but after the app getting crashed, how to call the action to send email/HTTP post method .

Please advise and thanks in advance .

Answer Source

The best way to handle crash logs is creating an UncaughtExceptionHandler and handling it as per your requirement. Create a BaseActivity class and extend all the Activities with that and put this code stuff in the BaseActivity class.

private Thread.UncaughtExceptionHandler handleAppCrash = 
                                         new Thread.UncaughtExceptionHandler() {
        public void uncaughtException(Thread thread, Throwable ex) {
            Log.e("error", ex.toString());
            //send email here

Then just enable is inside onCreate() method of your BaseActivity by using


So, now whenever there will be a crash in your Application uncaughtException() will be called and you will have to handle the crash accordingly.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download