Android: Log Logcat to file while runtime

While I was developing a app for Android I was looking for a way to get the logcat output after testing my app without an USB  debugging connection. The following code allows you to store the logcat log in a file, accessible via file explorer.

First you need the correct permissions in you manifest file:

I recommend to use a Application class at the beginning of you app.  That allows a proper file and log handling. Here is an example. That piece of code adds a new folder named  “MyPersonalAppFolder” with another folder called “log” in it to the public external storage. after that the logcat output is cleared and the new logcat output is written into a new file called logcatXXX.txt, where XXX is the are the milliseconds time at this moment.