という入力メソッドを実装しています。RemoteInputは、InputViewとキーボードを使用せずにInputMethodServiceを拡張するだけです。ユーザーがRemoteInputをデフォルトのIMEとして選択すると、RemoteInputは現在の入力ステータスを他のデバイスに送信し、ユーザーは遠隔から入力アクションを行うことができます。入力が完了すると、他のデバイスに入力されたテキストが現在のデバイスに返され、RemoteInputはInputConnection.commitText (CharSequence text, int newCursorPosition)
を使用して現在の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();
}
}