0

When I show the LogCat in Android, I want to clear the buffer Log programmatically.
But when I use this statement:

Runtime.getRuntime().exec("logcat -c")

It doesn't clear the buffer.
How can I solve this problem?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • You can check herer http://stackoverflow.com/questions/3315389/how-to-empty-the-logcat-buffer-in-android – Kabir Apr 27 '15 at 04:30
  • I want clear logcat in Code , by statement not by ADB . Can you give me other idea? – tuan nguyen Apr 27 '15 at 04:38
  • This will help you http://stackoverflow.com/questions/27678829/android-clear-log-programmatically – Kabir Apr 27 '15 at 04:40
  • thank you for your help . But it still had problem . I think I lack in permission to clear Log . My Device is SamSung Note 4 . OS : 4.4.4 – tuan nguyen Apr 27 '15 at 04:53
  • Then add `` to your manifest – Vrashabh Irde Apr 27 '15 at 06:32
  • `READ_LOGS` is no longer granted to apps since Jelly Bean – Marcin Orlowski Apr 29 '15 at 07:32
  • i am also trying to clear my logcat buffer through code, But its not working from code. Any idea ? – Rubanraj Ravichandran Aug 12 '15 at 07:29
  • I recently faced this issue. Runtime.getRuntime().exec("logcat -c") was working on some devices & failed on few. After a lot of research...my conclusion is  It is Android Operating System dependent process, which shows different behaviours for few Android API Levels (API 16 to API 21)  The Logcat command "logcat -c" is deprecated for API 16 to API 21, as this command clears the whole systems – Suyog Gunjal Dec 17 '15 at 10:28
  • Instead of clearing the log - just apply the timestamp filter https://stackoverflow.com/q/45416946/1778421 – Alex P. Jul 14 '18 at 16:52

2 Answers2

1

Runtime.getRuntime().exec("logcat -c") will clear only non-rooted log buffers (main, system ..etc). Please use Runtime.getRuntime().exec("logcat -b all -c") to clear all the buffers (like radio, kernel..etc)

Lava Sangeetham
  • 2,943
  • 4
  • 38
  • 54
0

I recently faced this issue. Runtime.getRuntime().exec("logcat -c") was working on some devices & failed on few. After a lot of research...my conclusion is

  1. It is Android Operating System dependent process, which shows different behaviours for few Android API Levels (API 16 to API 21)
  2. The Logcat command "logcat -c" is deprecated for API 16 to API 21, as this command clears the whole systems Logs

Instead of depending on Logcat process and writing logs to Logcat, create one custom file in app context (/data/data//files) and write all logs to this file.

Suyog Gunjal
  • 287
  • 4
  • 7