Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 hereenter image description hereenter image description hereenter image description here

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

like image 244
Aerial Avatar asked Dec 04 '22 04:12

Aerial


2 Answers

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);
    }
like image 76
Vishal Avatar answered Dec 26 '22 05:12

Vishal


It is easy just add the following code in your manifest for the desire activity:

android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="keyboardHidden"
like image 20
Buzz Avatar answered Dec 26 '22 05:12

Buzz