gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:47:08 43 4
gpt4 key购买 nike

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

当远程输入的文本是英文字符和数字时,它工作完美,但当涉及到其他字符时,就会出错。我发现 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();
}
}

最佳答案

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

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

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

关于android - InputConnection.commitText(CharSequence text, int newCursorPosition) 只能提交英文字符和数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15405253/

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com