Skip to content

Instantly share code, notes, and snippets.

@AAverin
Created November 24, 2015 17:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AAverin/67c234204fec53dff5aa to your computer and use it in GitHub Desktop.
Save AAverin/67c234204fec53dff5aa to your computer and use it in GitHub Desktop.
Share logcat for Android
public void shareLogcat() {
String sdcardPath = null;
String path = Environment.getExternalStorageDirectory() + "/my_application_folder";
File dir = new File(path);
if (dir.mkdirs() || dir.isDirectory()) {
sdcardPath = path + File.separator + "logcat_" + System.currentTimeMillis() + ".log";
}
if (sdcardPath == null) {
return;
}
File logFile = null;
try {
logFile = new File(sdcardPath);
String cmd = "logcat -d -f " + logFile.getAbsolutePath();
Runtime.getRuntime().exec(cmd);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///" + sdcardPath));
sendIntent.setType("message/rfc822");
sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "my@email.com" });
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Logcat report");
try {
startActivity(sendIntent);
} catch (ActivityNotFoundException e) {
}
try {
String cmd = "logcat -c";
Runtime.getRuntime().exec(cmd);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment