public static boolean isSoftKeyboardShown(InputMethodManager imm, View v) {
IMMResult result1 = new IMMResult();
int res;
imm.showSoftInput(v, 0, result1);
// if keyboard doesn't change, handle the keypress
res = result1.getResult();
if (res == InputMethodManager.RESULT_UNCHANGED_SHOWN ||
res == InputMethodManager.RESULT_UNCHANGED_HIDDEN) {
return true;
} else
return false;
}