Android logcat:使用电子邮件从设备发送日志条目 [英] Android logcat: Send log entries from device using email

查看:110
本文介绍了Android logcat:使用电子邮件从设备发送日志条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经向几个朋友发布了Android应用程序的Beta版.现在,我想修复测试期间出现的一些错误.

I have released a beta version of an Android app to a few friends. Now, I would like to fix some bugs that came up during the test period.

我已经设置了第三方崩溃报告实用程序,因此我可以轻松处理应用程序崩溃.但是,有些错误行为不会导致崩溃.在这种情况下,我想检查一下应用程序日志,看看出了什么问题.

I have set a third-party crash reports utility, so I can easily handle app crashes. However, there are some erroneous behaviours which are not causing crashes. In these cases, I would like to inspect the app logs and see what went wrong.

应用程序是否可以通过电子邮件发送其logcat条目?

  • There are many logging apps (android-log-collector, Log Viewer (logcat)) which can inspect and show logcat entries. However, these apps can't access other apps' logs since Android 4.1.
  • I don't mind taking a lot of space in the device - this feature is for beta testers only.
  • The solution should work without root or any other special permissions.

推荐答案

在您的主要活动的onDestroy中调用此方法.

Call this method in onDestroy of your main activity.

 public void SendLogcatMail(){

    // save logcat in file
    File outputFile = new File(Environment.getExternalStorageDirectory(),
            "logcat.txt");
    try {
        Runtime.getRuntime().exec(
                "logcat -f " + outputFile.getAbsolutePath());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

 //send file using email
 Intent emailIntent = new Intent(Intent.ACTION_SEND);
 // Set type to "email"
 emailIntent.setType("vnd.android.cursor.dir/email");
 String to[] = {"yourmail@gmail.com"};
 emailIntent .putExtra(Intent.EXTRA_EMAIL, to);
 // the attachment
 emailIntent .putExtra(Intent.EXTRA_STREAM, outputFile.getAbsolutePath());
 // the mail subject
 emailIntent .putExtra(Intent.EXTRA_SUBJECT, "Subject");
 startActivity(Intent.createChooser(emailIntent , "Send email..."));
 }

这篇关于Android logcat:使用电子邮件从设备发送日志条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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