Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save Logcat from Android app to txt file

I'm trying to get all my logcat, which I see in Android Studio (like here https://i.sstatic.net/sseEr.png), to save as a txt file directly on my device.

What I've tryed so far is this code in the onCreate:

File logFile = new File(LogcatDir.getAbsolutePath() + "/log.txt" );
try
{
    Process process = Runtime.getRuntime().exec( "logcat -c");
    process = Runtime.getRuntime().exec( "logcat -f " + logFile + " *:S MyActivity_BUT_WHAT_TO_PUT_HERE");
}
catch ( IOException e ) {e.printStackTrace();}

and in the manifest file:

<uses-permission android:name="android.permission.READ_LOGS" />

I intentionally did a parse Error like

long test = Long.parseLong("z");

but there was actually only this in the log.txt:

--------- beginning of /dev/log/main
--------- beginning of /dev/log/system

Does anyone know, what I have to code, that I get the whole logcat?

like image 409
Pixel_95 Avatar asked Oct 29 '25 11:10

Pixel_95


1 Answers

This worked for me it saves it in the main storage with this code:

Log.w("before","Logcat save");
try {
  Process process = Runtime.getRuntime().exec("logcat -d");
  process = Runtime.getRuntime().exec( "logcat -f " + "/storage/emulated/0/"+"Logging.txt");
}catch(Exception e)
{
  e.printStackTrace();
}

enter image description here

enter image description here

like image 128
ivan Avatar answered Nov 01 '25 14:11

ivan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!