InputConnection.commitText (CharSequence text, int newCursorPosition) can only commit English characters and numbers?
Asked Answered
R

1

6

I implement an input method called RemoteInput simply extend InputMethodService, without InputViews and no keyboards. When user select RemoteInput as default IME, RemoteInput will send the current input status to other device and user can do input action remotely(using our customerized protocol). When input done, the text entered in other device will be sent back to current device, then RemoteInput commit the text onto current UI component(such as EditText) using InputConnection.commitText (CharSequence text, int newCursorPosition).

It works perfect when remote-inputed text are English characters and numbers, but when it comes to other characters things go wrong. I have found that InputConnection.commitText filter other characters. For instance, I enterd hello你好, only hello be commited successfully. And more:

  • hello world ==> helloworld
  • hello,world!! ==> helloworld

Anything you tell about this will be helpful, thanks in advance.

Here is my code:

public class RemoteInput extends InputMethodService {
    protected static String TAG = "RemoteInput";

    public static final String ACTION_INPUT_REQUEST = "com.aidufei.remoteInput.inputRequest";
    public static final String ACTION_INPUT_DONE = "com.aidufei.remoteInput.inputDone";

    private BroadcastReceiver mInputReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            if (ACTION_INPUT_DONE.equals(intent.getAction())) {
                String text = intent.getStringExtra("text");
                Log.d(TAG, "broadcast ACTION_INPUT_DONE, input text: " + text);
                input(text);
            }
        }
    };

    @Override
    public void onCreate() {
        super.onCreate();

        registerReceiver(mInputReceiver, new IntentFilter(ACTION_INPUT_DONE));
    }

    @Override
    public View onCreateInputView() {
        //return getLayoutInflater().inflate(R.layout.input, null);
        return null;
    }

    @Override
    public boolean onShowInputRequested(int flags, boolean configChange) {
        if (InputMethod.SHOW_EXPLICIT == flags) {
            Intent intent = new Intent(ACTION_INPUT_REQUEST);
            getCurrentInputConnection().performContextMenuAction(android.R.id.selectAll);
            CharSequence text = getCurrentInputConnection().getSelectedText(0);
            intent.putExtra("text", text==null ? "" : text.toString());
            sendBroadcast(intent);
        }
        return false;
    }

    public void input(String text) {
        InputConnection inputConn = getCurrentInputConnection();
        if (text != null) {
            inputConn.deleteSurroundingText(100, 100);
            inputConn.commitText(text, text.length());
        }
        //inputConn.performEditorAction(EditorInfo.IME_ACTION_DONE);
    }

    @Override
    public void onDestroy() {
        unregisterReceiver(mInputReceiver);
        super.onDestroy();
    }
}
Roturier answered 14/3, 2013 at 9:17 Comment(0)
N
-2

If you are using a language other than English you are required to use Unicode. You need to attach your Unicode font to your project and set the typeface of the element (e.g. EditText) to the font you attached. See the following to find out how to add custom fonts to your app.

http://tharindudassanayake.wordpress.com/2012/02/25/use-sinhala-fonts-for-your-android-app/

The second option would be to root your device and install the required font.

Nabala answered 19/9, 2013 at 7:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.