输入法框架changeLog
cl.inputmethod_frameworks.1 API错误信息返回方式变更
下列模块内部接口使用业务逻辑返回值表示错误信息,不符合OpenHarmony接口错误码规范。在API9进行变更。
-
输入法框架模块:系统接口,@ohos.inputmethod.d.ts
-
输入法服务模块:系统接口,@ohos.inputmethodengine.d.ts
-
输入法ExtentionAbility模块:系统接口,@ohos.inputmethodextensionability.d.ts
-
输入法ExtentionContext模块:系统接口,@ohos.inputmethodextensioncontext.d.ts
-
输入法子类型模块:系统接口,@ohos.inputMethodSubtype.d.ts
异步接口:通过AsyncCallback或Promise的error对象返回错误信息。
同步接口:通过抛出异常的方式返回错误信息。
变更影响
基于此前版本开发的应用,需适配接口的错误信息返回方式,否则会影响原有业务逻辑。
关键接口/组件变更
在以下接口增加错误码处理:
- getSetting(): InputMethodSetting;
- getController(): InputMethodController;
- switchInputMethod(target: InputMethodProperty, callback: AsyncCallback
): void; - switchInputMethod(target: InputMethodProperty): Promise
; - switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallback
): void; - switchCurrentInputMethodSubtype(target: InputMethodSubtype): Promise
; - switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype, callback: AsyncCallback
): void; - switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype): Promise
; - listInputMethodSubtype(inputMethodProperty: InputMethodProperty, callback: AsyncCallback<Array
>): void; - listInputMethodSubtype(inputMethodProperty: InputMethodProperty): Promise<Array
>; - listCurrentInputMethodSubtype(callback: AsyncCallback<Array
>): void; - listCurrentInputMethodSubtype(): Promise<Array
>; - getInputMethods(enable: boolean, callback: AsyncCallback<Array
>): void; - getInputMethods(enable: boolean): Promise<Array
>; - showOptionalInputMethods(callback: AsyncCallback
): void; - showOptionalInputMethods(): Promise
; - stopInputSession(callback: AsyncCallback
): void; - stopInputSession(): Promise
; - showSoftKeyboard(callback: AsyncCallback
): void; - showSoftKeyboard():Promise
; - hideSoftKeyboard(callback: AsyncCallback
): void; - hideSoftKeyboard():Promise
; - hide(callback: AsyncCallback
): void; - hide(): Promise
; - onCreate(want: Want): void;
- onDestroy(): void; InputClient 接口下:
- sendKeyFunction(action: number, callback: AsyncCallback
): void; - sendKeyFunction(action: number): Promise
; - deleteForward(length: number, callback: AsyncCallback
): void; - deleteForward(length: number): Promise
; - deleteBackward(length: number, callback: AsyncCallback
): void; - deleteBackward(length: number): Promise
; - insertText(text: string, callback: AsyncCallback
): void; - insertText(text: string): Promise
; - getForward(length: number, callback: AsyncCallback
): void; - getForward(length: number): Promise
; - getBackward(length: number, callback: AsyncCallback
): void; - getBackward(length: number): Promise
; - getEditorAttribute(callback: AsyncCallback
): void; - getEditorAttribute(): Promise
; - moveCursor(direction: number, callback: AsyncCallback
): void; - moveCursor(direction: number): Promise
; InputMethodExtensionAbility 类下: - onCreate(want: Want): void;
- onDestroy(): void;
适配指导
异步接口以showOptionalInputMethods为例,示例代码如下:
callback回调:
import inputMethod from '@ohos.inputmethod';
let inputMethodSetting = inputMethod.getSetting();
try {
inputMethodSetting.showOptionalInputMethods((err, data) => {
if (err !== undefined) {
console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in showing optionalInputMethods.');
});
} catch (err) {
console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err));
}
Promise回调:
import inputMethod from '@ohos.inputmethod';
let inputMethodSetting = inputMethod.getSetting();
inputMethodSetting.showOptionalInputMethods().then((data) => {
console.info('Succeeded in showing optionalInputMethods.');
}).catch((err) => {
console.error('Failed to showOptionalInputMethods: ' + JSON.stringify(err));
})
cl.inputmethod_frameworks.2 API部分接口废弃
以下接口标记废除:
- getInputMethodSetting(): InputMethodSetting;
- getInputMethodController(): InputMethodController;
- listInputMethod(callback: AsyncCallback<Array
>): void; - listInputMethod(): Promise<Array
>; - displayOptionalInputMethod(callback: AsyncCallback
): void; - displayOptionalInputMethod(): Promise
; - stopInput(callback: AsyncCallback
): void; - stopInput(): Promise
; interface InputMethodProperty: - readonly packageName: string;
- readonly methodId: string;
- getInputMethodEngine(): InputMethodEngine;
- createKeyboardDelegate(): KeyboardDelegate;
- hideKeyboard(callback: AsyncCallback
): void; - hideKeyboard(): Promise
;
替代接口如下:
- getSetting(): InputMethodSetting;
- getController(): InputMethodController;
- getInputMethods(enable: boolean, callback: AsyncCallback<Array
>): void; - getInputMethods(enable: boolean): Promise<Array
>; - showOptionalInputMethods(callback: AsyncCallback
): void; - showOptionalInputMethods(): Promise
; - stopInputSession(callback: AsyncCallback
): void; - stopInputSession(): Promise
; interface InputMethodProperty: - readonly name: string;
- readonly id: string;
- getInputMethodAbility(): InputMethodAbility;
- getKeyboardDelegate(): KeyboardDelegate;
- hide(callback: AsyncCallback
): void; - hide(): Promise
;
特别注意: 使用getInputMethodAbility()接口获取到InputMethodAbility对象,代替使用getInputMethodEngine()接口获取InputMethodEngine对象。 使用InputMethodAbility中的方法,不要再使用InputMethodEngine中的方法。 使用InputMethodAbility中的on('inputStart')方法,获取到KeyboardController实例与InputClient实例,不要再使用InputMethodEngine中的on('inputStart')方法去获取TextInputClient实例。 之前:
inputMethodEngine.getInputMethodEngine().on('inputStart', (kbController, textClient) => {
let keyboardController = kbController;
let textInputClient = textClient; // 获取到TextInputClient实例
});
之后:
inputMethodEngine.getInputMethodAbility().on('inputStart', (kbController, client) => {
let keyboardController = kbController;
let inputClient = client; // // 获取到InputClient实例
});
cl.inputmethod_frameworks.3 API部分接口变更
变更前:
- listInputMethod(enable: boolean, callback: AsyncCallback<Array
>): void; - listInputMethod(enable: boolean): Promise<Array
>; - terminateSelf(callback: AsyncCallback
): void; - terminateSelf(): Promise
;
变更后:
- getInputMethods(enable: boolean, callback: AsyncCallback<Array
>): void; - getInputMethods(enable: boolean): Promise<Array
>; - destroy(callback: AsyncCallback
): void; - destroy(): Promise
;
删除API9接口:
- startAbility(want: Want, callback: AsyncCallback
): void; - startAbility(want: Want, options: StartOptions, callback: AsyncCallback
): void; - startAbility(want: Want, options?: StartOptions): Promise
;
其他新增接口:
-
on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void;
-
off(type: 'imeChange', callback?: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void;
-
interface InputMethodProperty:
- readonly label?: string;
- readonly icon?: string;
- readonly iconId?: number;
- extra: object;
-
interface InputMethodAbility:
- on(type: 'setSubtype', callback: (inputMethodSubtype: InputMethodSubtype) => void): void;
- off(type: 'setSubtype', callback?: (inputMethodSubtype: InputMethodSubtype) => void): void;