From c9531b29b07228e677cee4ff452d152900d5ddb6 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Fri, 19 Aug 2022 17:08:58 +0800 Subject: [PATCH] Signed-off-by: ma-shaoyin Changes to be committed: --- .../reference/apis/js-apis-inputmethod.md | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md b/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md index 4bc6f8c3d9..05dd6c8f33 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md +++ b/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md @@ -95,9 +95,17 @@ switchInputMethod(target: InputmethodProperty, callback: AsyncCallback<boolea **示例:** ```js - inputMethod.switchInputMethod({packageName:"com.ohos.inputApp", methodId:"InputDemoService"}).then(res => { - prompt.showToast({message:"切换输入法成功" + this.imeList[this.flag].packageName, duration: 200}); - }); +inputmethod.switchInputMethod({packageName:"com.example.kikakeyboard", methodId:"com.example.kikakeyboard"} ,(err,result) => { + if (err == undefined) { + console.info("switchInputMethod callback result---err: " + err.msg); + return; + } + if (result) { + console.info("Success to switchInputMethod.(callback)"); + } else { + console.info("Failed to switchInputMethod.(callback)"); + } +}); ``` ## inputMethod.switchInputMethod9+ switchInputMethod(target: InputmethodProperty): Promise<boolean> @@ -121,9 +129,18 @@ switchInputMethod(target: InputmethodProperty): Promise<boolean> ```js - inputMethod.switchInputMethod({packageName:"com.ohos.inputApp", methodId:"InputDemoService"}).then(res => { - prompt.showToast({message:"切换输入法成功" + this.imeList[this.flag].packageName, duration: 200}); - }); +async function InputMethod() { + await inputMethod.switchInputMethod({packageName:"com.example.kikakeyboard", + methodId:"com.example.kikakeyboard"}).then((result) => { + if (result) { + console.info("Success to switchInputMethod.(promise)"); + } else { + console.info("Failed to switchInputMethod.(promise)"); + } + }).catch((err) => { + console.info("switchInputMethod promise err: " + err.msg); + }); +} ``` ## InputMethodController -- GitLab