如何在 app android 中获取 adb 输出?

How to get the adb output in app android?

我有一个 root 设备,我通过在终端中执行此 adb 命令来检查软键盘是否可见:

adb shell dumpsys window InputMethod | grep "mHasSurface"

这是输出:

mHasSurface=true mShownPosition=[0,1176] isReadyForDisplay()=true hasSavedSurface()=false mWindowRemovalAllowed=false

我可以从我的应用程序(使用 root)执行相同的 adb 命令,但我不知道如何获取输出。有谁知道是否可以在应用程序中获取输出?提前谢谢你。

过了一段时间,找到了方法here:

            try {
                Process process = Runtime.getRuntime().exec(sCommand11);
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
                int status = process.waitFor();
                Timber.d(sSUCommand6 + " finished with status " + status);

                // Grab the results
                StringBuilder log = new StringBuilder();
                String line;
                while ((line = bufferedReader.readLine()) != null) {
                    log.append(line + "\n");
                }

                Timber.d("We have the input " + log.toString());

            } catch (Exception e) {
                Timber.e("Error occurred while copying file " + e.getMessage());
            }