HW key emulation

Put your problem here if it does not fit any of the other categories.

HW key emulation

Postby mihoelzl » Mon Apr 04, 2011 3:08 pm

Hi,

I am trying to implement a small soft keyboard which should simulate HW key events. There should be an Up-Key, a Down-Key and an OK and Cancel Button.

I made my own InputMethodService which is defined in the Manifest file:
Code: Select all
<service android:name="MyInputMethod"
                android:permission="android.permission.BIND_INPUT_METHOD">
            <intent-filter>
                <action android:name="android.view.InputMethod" />
            </intent-filter>
            <meta-data android:name="android.view.im" android:resource="@xml/method" />>
        </service>


Inside the service I want to send a KeyEvent to the current Activity. Referring to the Developer Guide I can do this with the following Code:
Code: Select all

      InputConnection ic = getCurrentInputConnection();
      long eventTime = SystemClock.uptimeMillis();
      ic.sendKeyEvent(new KeyEvent(eventTime, eventTime,
      KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_UP, 0, 0, 0, 0,
      KeyEvent.FLAG_SOFT_KEYBOARD|KeyEvent.FLAG_KEEP_TOUCH_MODE));


The Problem here: the InputConnection is null. I tried to manually bind the Service to the activity, start the service, add the Service as Inputmethod to an edittext but nothing seems to work. The InputMethodService does not start in the right LifeCycle.

What am I missing? Any help here?

Thanks,
Michael
mihoelzl
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Apr 04, 2011 3:04 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google Feedfetcher and 26 guests