rk3568 OpenHarmony4.0如何使用中文输入法

本文介绍了在rk3568开发板上基于OpenHarmony4.0release移植搜狗输入法的过程,解决原有英文输入法无中文的问题,展示了开发步骤和所需权限,并提供了相关资源链接。
摘要由CSDN通过智能技术生成

问题:rk3568开发板 OpenHarmony4.0release系统自带输入法kikaInput软件只有英文输入,不含中文输入,不方便。本文基于rk3568开发板 OpenHarmony4.0release移植了laval社区发布的开发者手机中的搜狗输入法(测试版),实现了中文输入,为OpenHarmony4.0release的其他开发板中文输入提供参考。

一、案例展示

1、运行条件

(1)rk3568 开发板

(2)系统:OpenHarmony4.0release

2、下载并运行开发案例

(1)OpenHarmony4.0release系统自带输入法kikaInput软件只有英文输入;

(2)下载开发案例,使用Deveco Studio(建议使用4.0.0.600版本)打开运行编译demo、下载应用到rk3568开发板;将狗输入法hap(测试版)安装到开发板上,效果如下图所示。打开demo自动查询设备已安装输入法,点击输入法切换按钮,再选择弹窗点击选择搜狗输入法(测试版)。

(3)搜狗输入法设置为当前输入法,可进行英文输入法与中文输入法切换,如下图

二、开发流程

1、需要申请的权限

(1)inputMethod.switchInputMethod 切换输入法,仅系统应用可用,需要权限:ohos.permission.CONNECT_IME_ABILITY

说明:调用到的API方法需要仅系统应用可用,因此需要将应用设置为系统应用,具体操作参考文章:OpenHarmony应用开发权限申请-CSDN博客 一、4小节

2、开发步骤:

(1)从开发者手机中提取搜狗输入法软件,将提取的搜狗输入法软件(测试版)安装到开发板(相关hap已打包,见附件资料),如

(2)getInputMethods方法获取已激活/未激活的输入法应用列表,

Button("输入法查询")
            .size({ width: 180, height: 50 })
            .fontSize(25)
            .stateStyles({
              pressed: {
                .backgroundColor(Color.Grey)
              },
              normal: {
                .backgroundColor(Color.Blue)
              }
            })
            .margin({ top: 10, bottom: 10 })
            .onClick(async () => {
              this.currentInputMethods = await this.inputMethodSetting.getInputMethods(true);
              this.otherInputMethods = await this.inputMethodSetting.getInputMethods(false);
              this.allInputMethods = this.currentInputMethods.concat(this.otherInputMethods);
              this.currentInputMethodSubtype = await this.inputMethodSetting.listCurrentInputMethodSubtype()
            })

(3)inputMethod.switchInputMethod方法切换输入法,仅系统应用可用。

try {
              inputMethod.switchInputMethod(item, (err: BusinessError, result: boolean) => {
                if (err) {
                  logger.info(`Failed to switchInputMethod: ${JSON.stringify(err)}`);
                  return;
                }
                if (result) {
                  logger.info('Succeeded in switching inputmethod.');
                if( this.confirm){
                  this.confirm();
                  promptAction.showToast({
                    message:"切换成功",
                    duration:500
                  })
                }

                } else {
                  logger.error('Failed to switchInputMethod.');
                  promptAction.showToast({
                    message:"切换失败",
                    duration:500
                  })
                }
              });
            } catch (err) {
              logger.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`);
            }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值