Android logcat: Send log entries from device using email

后端 未结 2 1287
無奈伤痛
無奈伤痛 2020-12-24 06:57

Scenario

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

相关标签:
2条回答
  • 2020-12-24 07:00

    It sounds like RemoteLogger is exactly what you need

    https://github.com/sschendel/RemoteLogger

    Capture debug logging to a file that user can easily send to you via email. This was created out of necessity to troubleshoot a non-reproducible bug reported by a user. To be clear the logging was dropped into a version of app released to test users to troubleshoot. Removed in final production code.

    Library provides hooks to start, stop, send, and delete log file.

    0 讨论(0)
  • 2020-12-24 07:02

    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..."));
     }
    
    0 讨论(0)
提交回复
热议问题