Android show softkeyboard with showSoftInput is not working?

I have created a trivial application to test the following functionality. When my activity launches, it needs to be launched with the softkeyboard open.

My code does not work?!

I have tried various “state” settings in the manifest and different flags in the code to the InputMethodManager (imm).

I have included the setting in the AndroidManifest.xml and explicitly invoked in the onCreate of the only activity.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
    <uses-sdk android:minSdkVersion="7" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".StudyImeActivity"
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />


… the main layout (main.xml) …

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""

… and the code …

public class StudyImeActivity extends Activity {
    private EditText mEditTextStudy;

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

        mEditTextStudy = (EditText) findViewById(;
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(mEditTextStudy, InputMethodManager.SHOW_FORCED);


This is so subtle, that it is criminal. This works on the phones that do NOT have a hard, slide-out keyboard. The phones with a hard keyboard will not open automatically with this call. My LG and old Nexus One do not have a keyboard — therefore, the soft-keyboard opens when the activity launches (that is what I want), but the MyTouch and HTC G2 phones that have slide-out keyboards do not open the soft keyboard until I touch the edit field with the hard keyboard closed.


jQuery keyboard events

Using jQuery, I would like to capture a keyboard event that is:

  • before the user lifts their finger from the key
  • after the characters from the keyboard event have registered in the input box.

To clarify, view this example. When keypress fires, the input value has not been updated yet.


Apparently I wasn’t clear as to what I need.

The function must be called before the user lifts their finger up from the key, but after the key’s character is placed in the input box. So the following do not work:

  • keydown: at the keypress event, the value in the text box has not been updated
  • keypress: at the keypress event, the value in the text box has not been updated
  • keyup: this is called when the user lifts their finger, which is too late.


You can use the input event, which works in recent versions of all major browsers:

var input = document.getElementById("your_input_id");
input.oninput = function() {

Unfortunately, it doesn’t work in IE <= 8. However, in those browsers you can use the propertychange event on the value property instead:

input.onpropertychange = function() {
    if (window.event.propertyName == "value") {

SO regular JavaScript answerer @Andy E has covered this in detail on his blog:


how to check if var is not empty with javascript?

Not having much luck with this. I’m trying to determine if a var is not empty.

$('#content').mouseup(function() {

    var selection = getSelected();

    if (typeof(selection) !=='undefined') {

What this is doing is grabbing any text the user has selected — but it shows an empty alert even if the user just mouseup’s on the div.


Your code is perfectly accurate for detecting an undefined value, which means that the function always returns some kind of value even if there is no selection.

If the function for example returns a selection object (like the window.getSelection function), you check the isCollapsed property to see if the selection is empty:

if (!selection.isCollapsed) ...

Android: what is the difference between resolution and density?

according to Android definitions, i’ve found that:

Resolution: The total number of physical pixels on a screen

Density: Based on the screen resolution, the spread of pixels across the physical width and height of the screen.

Can anyone help me to understand better the differences between the two definitions?

Thanks in advance


Resolution is about how many pixels you can show on screen.

Density is based on your device real size, if it’s small and has a higher resolution, than the density is high cause you show more pixels in less physical space.


How to determine the voicemail phone number in Android

How can I determine the phone’s voicemail number in Android code?


You can use getVoiceMailNumber() in the TelephonyManager class, please note that this may not work with all cell phone providers:

Android TelephonyManager

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..