问题
In my onCreateInputView of InputMethodService I have a BroadcastReceiver, that listens for events from my application. My BroadcastReceiver get the text and try to insert into current text field.problem is text never inserted into the current textfield everthing working fine except text not inseted in editText filed.
Here I am posting my code snippset
@Override
public View onCreateInputView() {
kv = (KeyboardView) getLayoutInflater().inflate(R.layout.activity_main, null);
keyboard = new Keyboard(this, R.xml.qwerty);
kv.setKeyboard(keyboard);
kv.setOnKeyboardActionListener(this);
broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String resultData = intent.getStringExtra(Main2Activity.SERVICE_MESSAGE);
InputConnection ic = getCurrentInputConnection();
if (ic != null) {
ic.commitText(resultData, resultData.length());
}
}
};
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
lbm.registerReceiver(broadcastReceiver, new IntentFilter(Main2Activity.SERVICE_RESULT));
return kv;
}
来源:https://stackoverflow.com/questions/56971234/inputconnection-text-committing-not-working