Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android logcat: Send log entries from device using email

Tags:

android

logcat

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 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.

Is there a way for the app to send its logcat entries via email?

Clarifications

  • 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.
like image 647
Adam Matan Avatar asked Sep 10 '14 12:09

Adam Matan


People also ask

How do I send Logcat?

Tap the ellipses, and select “send” to email the log as an attached text file along with general device information. That's it!

How do I capture logs on my Android phone?

Navigate to device settings and enable Developer Options (see section for ADB logs) Navigate to Developer Options and tap on Take/Submit Bug Report. Select Full Report when prompted to get the full device info along with the logs.


1 Answers

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[] = {"[email protected]"};  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..."));  } 
like image 184
Aniruddh Rathore Avatar answered Oct 05 '22 16:10

Aniruddh Rathore