Search code examples
androidmobileadbroot

How to get the adb output in app android?


I have a rooted device where I am checking if the soft keyboard is visible by executing this adb command in the terminal:

adb shell dumpsys window InputMethod | grep "mHasSurface"

and this is the output:

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

I am able to execute the same adb command from my app (using root) but I don't know how to get the output. Does anyone know if its possible to get the output in app? Thank you in advance.


Solution

  • After a while, found a way to do it 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());
                }