【问题标题】:How to get the adb output in app android?如何在应用程序 android 中获取 adb 输出?
【发布时间】:2020-07-03 11:27:16
【问题描述】:

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

adb shell dumpsys window InputMethod | grep "mHasSurface"

这是输出:

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

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

【问题讨论】:

  • 能否请您发布用于在您的应用中执行相同命令的代码?

标签: android mobile adb root


【解决方案1】:

过了一会儿,找到了办法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());
            }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-19
    • 1970-01-01
    • 2013-03-15
    • 2012-04-21
    • 2014-01-07
    • 1970-01-01
    • 2014-10-12
    相关资源
    最近更新 更多