为了账号安全,请及时绑定邮箱和手机立即绑定

如何将 InputMethodService 与服务连接?

如何将 InputMethodService 与服务连接?

冉冉说 2022-12-15 15:53:46
我想将扩展 InputMethodService 的自定义软键盘与另一个服务连接。我需要从通用服务调用我的软键盘中的方法。问题是我无法扩展 Binder 类,因为 onBind() 方法在 AbstractInputMethodService 中定义为 final ...现在,如何从其他服务调用我的 SoftKeyboard 类中的方法?
查看完整描述

1 回答

?
慕运维8079593

TA贡献1876条经验 获得超5个赞

我已经通过使用广播接收器类解决了这个问题。


    class MyReceiver extends BroadcastReceiver {

    @Override

    public void onReceive(Context context, Intent intent) {

        if (intent.getAction().equals("GET_KEY_KEY")) {

            String msg = intent.getStringExtra("msg");

                InputConnection ic = getCurrentInputConnection();

                if (ic != null) {

                    ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_RIGHT));

                }

        }


    }

}

然后我向我的服务发送了一个广播。


                Intent intent = new Intent();

            intent.setAction("GET_KEY_KEY");

            sendBroadcast(intent);


查看完整回答
反对 回复 2022-12-15
  • 1 回答
  • 0 关注
  • 50 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信