admin管理员组文章数量:1632346
问题: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)}`);
}
版权声明:本文标题:rk3568 OpenHarmony4.0如何使用中文输入法 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dongtai/1729127843a1187513.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论