In my case, I need to open the keyboard within onActivityResult()
after getting a picture from Gallery or taking a picture via camera.
To make it works, I have to put a delay like 500 ms. Otherwise, it will not open the keyboard.
Here is my code inside onActivityResult()
:
// Set original file name to description.
EditText etDescription = getView().findViewById(R.id.etAttachmentDescription);
etDescription.setText(fileName);
etDescription.selectAll();
etDescription.requestFocus();
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
// Open keyboard after 500ms
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
}
}, 500);