Search code examples
androidandroid-intentkeyboardmessage

How to hide keyboard automatically after sending e-mail using emailIntent


There is a page where the user can send e-mail, sms or call its guests when needed. The problem is that when the user sends e-mail to its guest, the keyboard doesn't hide. Even-though I have a small problem solving the issue, It still seems hard to find alike post to solve it. I'll be also making screenshots and placing them in here.

enter image description here enter image description here enter image description here enter image description here

As you can see, the keyboard doesn't hide after sending mail.


Solution

  • Intent sendIntent = new Intent(Intent.ACTION_SEND);
                                sendIntent.setType("text/plain");
                                sendIntent.putExtra(Intent.EXTRA_EMAIL,
                                        new String[] { **EmailAddress** });
                                startActivityForResult(sendIntent, 1);
    
    
    
    
       @Override
        protected void onActivityResult(int arg0, int arg1, Intent arg2) {
            super.onActivityResult(arg0, arg1, arg2);
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    InputMethodManager inputManager = (InputMethodManager) activity
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    inputManager.hideSoftInputFromWindow(**AnyViewOfScreen**.getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
                }
            }, 300);
        }