InputConnection.commitText (CharSequence text, int newCursorPosition) can only transmit English characters and numbers?

I implement the RemoteInput input method by simply extending the InputMethodService, without InputViews and without a keyboard. When the user selects RemoteInput as the default IME, RemoteInput sends the current input status to another device, and the user can remotely perform input actions (using our client protocol). When the input is complete, the text entered into another device will be sent back to the current device, and then RemoteInput will transfer the text to the current user interface component (e.g. EditText) using InputConnection.commitText (CharSequence text, int newCursorPosition) .

It works great when text with remote input is English characters and numbers, but when it comes to other characters, things go wrong. I found that InputConnection.commitText filters other characters. For example, I entered helloไฝ ๅฅฝ , successfully completed only hello . And further:

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

Everything that you tell about this will be useful, 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(); } } 
+6
source share
1 answer

If you use a language other than English, you must use Unicode. You need to attach the Unicode font to your project and set the font of the element (for example, EditText) to the font you attached. To learn how to add custom fonts to your application, follow these steps:

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

The second option is to shorten your device and install the required font.

-2
source

All Articles