0

I want read logcat in my test:

    fun threadOperation() {
        val processBuilder = ProcessBuilder(arrayListOf("/bin/sh", "-c", "logcat"))
        var process: Process? = null
        try {
            process = processBuilder.start()
            val stderrStream = process.errorStream
            val stdoutStream = process.inputStream

            BufferedReader(InputStreamReader(stdoutStream)).use {
                while (true) {
                    val line = it.readLine() ?: break
                    logList?.add(line)
                }
            }

            BufferedReader(InputStreamReader(stderrStream)).use {
                while (true) {
                    val line = it.readLine() ?: break
                    logList?.add(line)
                }
            }
        } catch (e: IOException) {
            print(0)
        }
    }

But I can't read all log in logcat and give 5-6 string in my list(only logs in Console) How get all logcat?

I try other params And this command work in terminal User permission add:

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

Second varian write not all logcat:

fun threadOperation() {
        try {
            val process = Runtime.getRuntime().exec("logcat -d")

            val bufferedReader = BufferedReader(
                InputStreamReader(process.inputStream)
            )

            val log = StringBuilder()
            var line: String?
            while (bufferedReader.readLine().also { line = it } != null) {
                logList.add(line)
            }
        } catch (e: IOException) {
            print(0)
        }
    }
Lino
  • 5,084
  • 3
  • 21
  • 39
Red Cape
  • 13
  • 3

0 Answers0