Execute Commands using Shizuku API

Поділитися
Вставка
  • Опубліковано 20 жов 2024
  • Today i show you how to execute commands using Shizuku API on android within your app
    Method to execute the commands:
    private fun executeShellCommandWithShizuku(command: String) {
    try {
    // Split the command into an array
    val cmd = command.split(" ".toRegex()).dropLastWhile { it.isEmpty() }
    .toTypedArray()
    // Execute the command using ShizukuRemoteProcess
    val process = Shizuku.newProcess(cmd, null, null)
    // Read the output from the process
    val reader = BufferedReader(InputStreamReader(process.inputStream))
    val output = StringBuilder()
    var line: String?
    while (reader.readLine().also { line = it } != null) {
    output.append(line).append("
    ")
    }
    reader.close()
    // Print the output
    Log.d("powermanager", output.toString())
    // Wait for the process to finish
    process.waitFor()
    } catch (e: java.lang.Exception) {
    e.printStackTrace()
    Log.e("powermanager", e.message!!)
    }
    }
    Shizuku
    API
    android
    How to execute commands on androids
    shell script
    root rights
    ADB rights
    Music: Syn Cole - Feel Good

КОМЕНТАРІ • 2