has.callNative(string|Object params)
Provides an API for synchronously calling a local method.
Required permission: Before development, you need to apply for the permission for communication between atomic service frameworks. For details about the integration process, see Inter-Framework Communication.
Since: 1.0.22
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| params | string | Object | Yes | Used to call the local asynchronous method. |
Error code information
| Error Code | Error Message |
|---|---|
| 102 | Parameter error. Possible causes: 1.params is required. 2.check type is invalid. |
| 103 | callNative has no permission. |
Example:
const res = has.callNative('getSystemInfo');
console.info('callNative getSystemInfo res: ', res);
const sumRes = has.callNative({
action: 'calculate',
args: [1, 2, 3, 4, 5]
});
console.info('callNative calculate res: ', sumRes); has.callNativeAsync(Object object)
Provides an API for asynchronously calling a local method.
Required permission: Before development, you need to apply for the permission for communication between atomic service frameworks. For details about the integration process, see Inter-Framework Communication.
Since: 1.0.22
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| params | string|Object | Yes | Used to call the local asynchronous method. |
| success | function | No | Callback triggered when the API call is successful. |
| fail | function | No | Callback triggered when the API call fails. |
| complete | function | No | Callback triggered when the API call is complete, regardless of success or failure. |
Error code information
| Error Code | Error Message |
|---|---|
| 102 | Parameter error. Possible causes: 1.params is required. 2.check type is invalid. |
| 103 | callNative has no permission. |
| 10000402 | callNativeAsync failed/error. |
Example:
has.callNativeAsync({
params: 'getSystemInfo',
success: (res) => {
console.info('callNativeAsync getSystemInfo success:', res);
},
fail: (err) => {
console.error('callNativeAsync getSystemInfo fail:', err);
},
complete: (res) => {
console.info('callNativeAsync getSystemInfo complete:', res);
}
});
has.callNativeAsync({
params: { action: 'makeCall', args: '13112341234' },
success: (res) => {
console.info('callNativeAsync makeCall success:', res);
},
fail: (err) => {
console.error('callNativeAsync makeCall fail:', err);
},
complete: (res) => {
console.info('callNativeAsync makeCall complete:', res);
}
});