InputConnection.commitText(CharSequence text,int newCursorPosition)只能提交英文字符和数字?

iSt*_*tar 6 android android-softkeyboard android-input-method

我实现了一个名为RemoteInput的输入方法,只是扩展InputMethodService,没有InputViews而没有键盘.当用户选择RemoteInput作为默认IME时,RemoteInput会将当前输入状态发送给其他设备,用户可以远程执行输入操作(使用我们的定制协议).输入完成后,在其他设备中输入的文本将被发送回当前设备,然后RemoteInput将文本提交到当前UI组件(如EditText)上InputConnection.commitText (CharSequence text, int newCursorPosition).

当远程输入的文本是英文字符和数字时,它是完美的,但是当涉及到其他字符时出现问题.我发现InputConnection.commitText过滤其他字符.例如,我输入hello??,只能hello成功提交.和更多:

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

你提出的任何事情都会有所帮助,在此先感谢你们.

这是我的代码:

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();
    }
}
Run Code Online (Sandbox Code Playgroud)

ThE*_*FuL -2

如果您使用英语以外的语言,则需要使用 Unicode。您需要将 Unicode 字体附加到项目中,并将元素的字体(例如 EditText)设置为您附加的字体。请参阅以下内容,了解如何将自定义字体添加到您的应用程序。

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

第二个选项是root您的设备并安装所需的字体。