Created
May 29, 2016 21:41
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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