0
1

More than 1 year has passed since last update.

【Android】プログラム上でadb shellコマンドを実行する方法

Posted at

プログラム上でadb shellコマンドを実行する方法

パッケージ名を指定して、別プロセスのアプリを終了させる場合

exec()の引数を変更することで様々なコマンドを実行できます

「adb」は省略してexec()に渡します

main.kt
class AdbService() {

    fun killProcess(packageName: String) {

        //adbから実行する場合は、「adb shell am force-stop com.google.android.apps.maps」となる
        val process = Runtime.getRuntime().exec("am force-stop $packageName")
        process.waitFor()

    }

    init {

        //GoogleMapを終了させる場合
        val googleMapPackageName = "com.google.android.apps.maps"
        killProcess(googleMapPackageName)

    }

}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1