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?
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();
}


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