Skip to content

Instantly share code, notes, and snippets.

@TimB0
Created May 29, 2016 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TimB0/76019165171bd4abb14019c22c9b89ef to your computer and use it in GitHub Desktop.
Save TimB0/76019165171bd4abb14019c22c9b89ef to your computer and use it in GitHub Desktop.
A Java function to use in a UiAutomator test to find out whether the Android keyboard is open or not
public boolean isKeyboardDisplayed() {
String checkKeyboardCommand = "dumpsys input_method | grep mInputShown";
try {
Process process = Runtime.getRuntime().exec(checkKeyboardCommand);
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
int read;
char[] buffer = new char[4096];
StringBuffer output = new StringBuffer();
while ((read = reader.read(buffer)) > 0) {
output.append(buffer, 0, read);
}
reader.close();
process.waitFor();
if (output.toString().contains("mInputShown=true")) {
return true;
} else {
return false;
}
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment