Skip to content

Commit

Permalink
examples: fix #14 opening keyboard on Android API level 33
Browse files Browse the repository at this point in the history
  • Loading branch information
larpon committed Nov 12, 2024
1 parent e5eb342 commit 4928c2b
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ protected void onDestroy() {
protected void onPause(){
super.onPause();
thiz.hideSoftKeyboard();
}
}

@Override
@Override
protected void onResume(){
super.onResume();
if(thiz.hiddenEditText == null) {
return;
}
thiz.showSoftKeyboard();
}
}

public static void setSoftKeyboardBuffer(String text) {
public static void setSoftKeyboardBuffer(String text) {
if(thiz.hiddenEditText == null) {
Log.e(TAG,"No keyboard initalized");
return;
Expand All @@ -88,7 +88,7 @@ public void run() {
});
}

public static void showSoftKeyboard() {
public static void showSoftKeyboard() {
//Log.d(TAG,"showSoftKeyboard called");

final EditText editText = new EditText(thiz);
Expand All @@ -110,7 +110,13 @@ public void run() {
editText.requestFocus();

InputMethodManager imm = (InputMethodManager) thiz.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

if (android.os.Build.VERSION.SDK_INT < 33) {
// NOTE: deprecated in "TIRAMISU" (API 33)
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
} else {
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
}

editText.addTextChangedListener(new TextWatcher() {

Expand Down

0 comments on commit 4928c2b

Please sign in to comment.