1

I need to detect hidden key board when hidden keyboard is pressed
My source code

<activity
    android:name="com.teamios.info.activity.MainScreenActivity"
    android:screenOrientation="landscape"
    android:theme="@style/Theme.MyScreenTranNorman"
    android:configChanges="orientation|keyboardHidden"
    android:windowSoftInputMode="stateUnchanged|adjustPan" />

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    Toast.makeText(this, "keyboard visible", Toast.LENGTH_SHORT).show();
}

I tested in samsung galaxy nexus phone android os 4.2.1, but Toast didn't show when keyboard hidden Please help me.

wind
  • 63
  • 1
  • 3
  • 9
  • try this code Toast.makeText(MainActivity.this, "keyboard visible 1", Toast.LENGTH_SHORT).show(); – ADT Sep 11 '13 at 07:42
  • The problem is when keyboard show/hide then onConfigurationChanged function isn't called – wind Sep 11 '13 at 08:28
  • I'm having this same issue on Android 4.4.4 (Cyanogenmod) for an S4 (GT-i9505G). I have an identical phone running 5.0 (Google Play Edition) and it gets the onConfigurationChanged() call just fine. On the 4.4.4 device, the keyboard actually connects and can type characters into my app, but the app is not informed when attachment occurs. May be an OS bug. – Carl Jun 08 '15 at 08:31

2 Answers2

1
 <activity
        android:name="com.teamios.info.activity.MainScreenActivity"
        android:theme="@style/Theme.MyScreenTranNorman"
        android:configChanges="orientation|keyboardHidden"
        android:windowSoftInputMode="stateUnchanged|adjustPan" />

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
    if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
        Toast.makeText(this, "keyboard visible", Toast.LENGTH_SHORT).show();
    } else if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
        Toast.makeText(this, "keyboard hidden", Toast.LENGTH_SHORT).show();
    }
    }

And add

<activity android:name=".MyActivity" android:screenOrientation="landscape " > </activity>

in menifest class.

John R
  • 2,078
  • 8
  • 35
  • 58
  • The problem is when keyboard show/hide then onConfigurationChanged function isn't called – wind Sep 11 '13 at 08:29
  • @wind delete this from android:screenOrientation="landscape" from your code. And add in manifest class. – John R Sep 11 '13 at 08:56
  • Thank John R, It is not work – wind Sep 11 '13 at 09:22
  • Yes, still same problem. When screen Orientation is change, onConfigurationChanged function is called but when keyboard is show/hide then not call onConfigurationChanged function . – wind Sep 11 '13 at 09:32
  • @Jon R: This problem, onConfigurationChanged function isn't called – wind Sep 11 '13 at 10:41
  • in menifest class what is the name you are writing for this activity? – John R Sep 11 '13 at 10:45
  • The activity's name is MainScreenActivity.class – wind Sep 11 '13 at 11:00
  • write .MainScreenActivity only. – John R Sep 11 '13 at 11:05
  • I changed it but it still same problem – wind Sep 11 '13 at 11:13
  • @Jon R: Do you have sample source code? Can you send to me by email (hovietlu@gmail.com) – wind Sep 11 '13 at 11:24
  • check these links maybe you get some help. http://stackoverflow.com/questions/5620033/onconfigurationchanged-not-getting-called http://stackoverflow.com/questions/6359328/android-onconfigurationchanged-is-not-being-called-in-activity – John R Sep 11 '13 at 11:42
0

Did you add android:configChanges="keyboardHidden" in your manifest file ?

user1764879
  • 112
  • 1
  • 9
  • Yes, I did. In manifest i config below android:configChanges="orientation|keyboardHidden" – wind Sep 11 '13 at 08:50