获取崩溃日志,并将其作为电子邮件发送 [英] Getting the crash log and send it as email

查看:117
本文介绍了获取崩溃日志,并将其作为电子邮件发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的搜索,我得到了低于code获取崩溃日志。

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) 
      {
        log.append(line);
      }

但我在哪里添加此code,所以,我应该得到的崩溃报​​告每当我的应用程序崩溃。

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

此外,我想通过电子邮件发送或发送到服务器,但应用程序越来越坠毁后,如何调用动作发送电子邮件/ HTTP POST方法。

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 .

推荐答案

办理崩溃日志的最好的方法是创建一个的UncaughtExceptionHandler 和处理是按您的要求。创建一个 BaseActivity 类,并一直延伸活动,这一点,把这个code的东西在 BaseActivity 类。

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() {
        @Override
        public void uncaughtException(Thread thread, Throwable ex) {
            Log.e("error", ex.toString());
            //send email here
        }
    };

然后就能够在里面的onCreate()你的 BaseActivity 使用方法

Thread.setDefaultUncaughtExceptionHandler(handleAppCrash);

所以,现在每当有会在你的应用程序崩溃 uncaughtException()将被调用,你将不得不相应地处理崩溃。

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

这篇关于获取崩溃日志,并将其作为电子邮件发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆