Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.
HarmonyOS
smartMobilityCommon is provided as a common function for apps to listen to the status of distributed services (such as HiCar and Super Home Screen) and implement event listening.
Since: 5.0.0(12)
import { smartMobilityCommon } from '@kit.CarKit'; Common event.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.CarService.DistributedEngine
Since: 5.0.0(12)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| eventName | string | No | No | Event name, which is defined by the service party. |
| type | SmartMobilityType | No | No | Service type. |
| data | Record<string, Object> | No | No | Detailed event information, which is determined jointly by the smart mobility service and app parties. |
Smart mobility status information, including the current service type, connection status, and service data.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.CarService.DistributedEngine
Since: 5.0.0(12)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| status | SmartMobilityStatus | No | No | Service connection status. |
| type | SmartMobilityType | No | No | Service type. |
| data | Record<string, Object> | No | No | Detailed connection information, which is determined jointly by the smart mobility service and app parties. |
Enumerated values of the service connection status.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.CarService.DistributedEngine
Since: 5.0.0(12)
| Name | Value | Description |
|---|---|---|
| IDLE | 0 | The service is in the idle state. This is the default value when the service is not started. |
| RUNNING | 1 | The service is running. |
Enumerated values of the service type.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.CarService.DistributedEngine
Since: 5.0.0(12)
| Name | Value | Description |
|---|---|---|
| HICAR | 0 | HiCar. |
| SUPER_LAUNCHER | 1 | Super Home Screen. |
| CAR_HOP | 2 | Hop. |
getSmartMobilityAwareness(): SmartMobilityAwareness
Obtains SmartMobilityAwareness.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.CarService.DistributedEngine
Device behavior differences: For 6.0.0(22) and earlier versions, this API is supported on phones. On other device types, it returns error code 801. For 6.1.0(23) and later versions, this API is supported on both phones and tablets, but does not respond on other device types.
Required permission: ohos.permission.ACCESS_CAR_DISTRIBUTED_ENGINE
Since: 5.0.0(12)
Returns:
| Type | Description |
|---|---|
| SmartMobilityAwareness | Smart mobility management class. |
Example:
import { smartMobilityCommon } from '@kit.CarKit';
let awareness: smartMobilityCommon.SmartMobilityAwareness = smartMobilityCommon.getSmartMobilityAwareness(); Error codes:
For details about the error codes, please refer to Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 801 | Capability not supported. |
Smart mobility management class, which is used to call smart mobility APIs.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.CarService.DistributedEngine
Since: 5.0.0(12)
on(type: 'smartMobilityEvent', smartMobilityTypes: SmartMobilityType[],callback: Callback<SmartMobilityEvent>): void
Registers an event listener of the smart mobility service. For example, this callback is triggered when a navigation hop is complete. This API uses an asynchronous callback to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.CarService.DistributedEngine
Device behavior differences: For 6.0.0(22) and earlier versions, this API is supported on phones. On other device types, it returns error code 801. For 6.1.0(23) and later versions, this API is supported on both phones and tablets, but does not respond on other device types.
Required permission: ohos.permission.ACCESS_CAR_DISTRIBUTED_ENGINE
Since: 5.0.0(12)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Subscription type. The value is a constant: smartMobilityEvent, which indicates registering an event listener. |
| smartMobilityTypes | SmartMobilityType[] | Yes | Service type array, which can contain multiple services. |
| callback | Callback<SmartMobilityEvent> | Yes | Mobility service event callback function, which returns the common event object of smart mobility. |
Error codes:
For details about the error codes, please refer to Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed; 4. The size of specified type is greater than 255. |
| 801 | Capability not supported. |
Example:
import { smartMobilityCommon } from '@kit.CarKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
try {
// Obtain the SmartMobilityAwareness instance.
let awareness: smartMobilityCommon.SmartMobilityAwareness = smartMobilityCommon.getSmartMobilityAwareness();
// Service type.
let types: smartMobilityCommon.SmartMobilityType[] = [smartMobilityCommon.SmartMobilityType.CAR_HOP];
// Mobility service event callback function.
const callBack = (event: smartMobilityCommon.SmartMobilityEvent) => {
hilog.info(0x0000, 'testTag', 'Received smart mobility event: ', JSON.stringify(event));
};
// Register a mobility service event listener.
awareness.on('smartMobilityEvent', types, callBack);
} catch (e) {
// Obtain the error code for an API call exception and handle the exception.
hilog.error(0x0000, 'testTag', `on smart mobility event error, error code: ${e?.code}`);
} off(type: 'smartMobilityEvent', smartMobilityTypes: SmartMobilityType[], callback?: Callback<SmartMobilityEvent>): void
Unregisters a smart mobility service event listener. This API uses an asynchronous callback to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.CarService.DistributedEngine
Device behavior differences: For 6.0.0(22) and earlier versions, this API is supported on phones. On other device types, it returns error code 801. For 6.1.0(23) and later versions, this API is supported on both phones and tablets, but does not respond on other device types.
Required permission: ohos.permission.ACCESS_CAR_DISTRIBUTED_ENGINE
Since: 5.0.0(12)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Subscription type. The value is a constant: smartMobilityEvent, which indicates unregistering an event listener. |
| smartMobilityTypes | SmartMobilityType[] | Yes | Service type array, which can contain multiple services. |
| callback | Callback<SmartMobilityEvent> | No | Callback function to be unregistered, which must be the same as that passed upon subscription. If this parameter is not passed, all callback functions will be unregistered. |
Error codes:
For details about the error codes, please refer to Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed; 4. The size of specified type is greater than 255. |
| 801 | Capability not supported. |
Example:
import { smartMobilityCommon } from '@kit.CarKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
try {
// Obtain the SmartMobilityAwareness instance.
let awareness: smartMobilityCommon.SmartMobilityAwareness = smartMobilityCommon.getSmartMobilityAwareness();
// Service type.
let types: smartMobilityCommon.SmartMobilityType[] = [smartMobilityCommon.SmartMobilityType.CAR_HOP];
// Mobility service event callback function.
const callBack = (event: smartMobilityCommon.SmartMobilityEvent) => {
hilog.info(0x0000, 'testTag', 'Received smart mobility event: ', JSON.stringify(event));
};
// Unregister the mobility service event listener.
awareness.off('smartMobilityEvent', types, callBack);
} catch (e) {
// Obtain the error code for an API call exception and handle the exception.
hilog.error(0x0000, 'testTag', `off smart mobility event error, error code: ${e?.code}`);
} getSmartMobilityEvent(type: SmartMobilityType, eventName: string): SmartMobilityEvent
Obtains the information about a specified event.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.CarService.DistributedEngine
Device behavior differences: For 6.0.0(22) and earlier versions, this API is supported on phones. On other device types, it returns error code 801. For 6.1.0(23) and later versions, this API is supported on both phones and tablets, but does not respond on other device types.
Required permission: ohos.permission.ACCESS_CAR_DISTRIBUTED_ENGINE
Since: 5.0.0(12)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| type | SmartMobilityType | Yes | Service type. |
| eventName | string | Yes | Event name. The options are as follows: CAR_HOP_EVENT: hop event HICAR_EVENT: HiCar event SUPER_LAUNCHER_EVENT: Super Home Screen event For other values, the API returns error code 401. |
Returns:
| Type | Description |
|---|---|
| SmartMobilityEvent | Common event information. |
Error codes:
For details about the error codes, please refer to Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed; 4. The size of specified type is greater than 255. |
| 801 | Capability not supported. |
Example:
import { smartMobilityCommon } from '@kit.CarKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
try {
// Obtain the SmartMobilityAwareness instance.
let awareness: smartMobilityCommon.SmartMobilityAwareness = smartMobilityCommon.getSmartMobilityAwareness();
// Service type.
let type = smartMobilityCommon.SmartMobilityType.CAR_HOP;
// Event name.
let eventName: string = 'CAR_HOP_EVENT';
// Obtain the common event information.
let event: smartMobilityCommon.SmartMobilityEvent = awareness.getSmartMobilityEvent(type, eventName);
hilog.info(0x0000, 'testTag', `get smart mobility event succeed, event: ${JSON.stringify(event)}`);
} catch (e) {
// Obtain the error code for an API call exception and handle the exception.
hilog.error(0x0000, 'testTag', `get smart mobility event error, error code: ${e?.code}`);
} on(type: 'smartMobilityStatus', smartMobilityTypes: SmartMobilityType[], callback: Callback<SmartMobilityInfo>): void
Registers a smart mobility connection status listener. This API uses an asynchronous callback to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.CarService.DistributedEngine
Device behavior differences: For 6.0.0(22) and earlier versions, this API is supported on phones. On other device types, it returns error code 801. For 6.1.0(23) and later versions, this API is supported on both phones and tablets, but does not respond on other device types.
Required permission: ohos.permission.ACCESS_CAR_DISTRIBUTED_ENGINE
Since: 5.0.0(12)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Subscription type. The value is a constant: smartMobilityStatus, which indicates registering a service connection status listener. |
| smartMobilityTypes | SmartMobilityType[] | Yes | Service type array, which can contain multiple services. |
| callback | Callback<SmartMobilityInfo> | Yes | Mobility connection status callback function, which returns the status information object of smart mobility. |
Error codes:
For details about the error codes, please refer to Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed; 4. The size of specified type is greater than 255. |
| 801 | Capability not supported. |
Example:
import { smartMobilityCommon } from '@kit.CarKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
try {
// Obtain the SmartMobilityAwareness instance.
let awareness: smartMobilityCommon.SmartMobilityAwareness = smartMobilityCommon.getSmartMobilityAwareness();
// Service type.
let types: smartMobilityCommon.SmartMobilityType[] = [smartMobilityCommon.SmartMobilityType.HICAR];
// Mobility connection status callback function.
const callBack = (info: smartMobilityCommon.SmartMobilityInfo) => {
hilog.info(0x0000, 'testTag', 'Received smart mobility info: ', JSON.stringify(info));
};
// Register a smart mobility connection status listener.
awareness.on('smartMobilityStatus', types, callBack);
} catch (e) {
// Obtain the error code for an API call exception and handle the exception.
hilog.error(0x0000, 'testTag', `on smart mobility status error, error code: ${e?.code}`);
} off(type: 'smartMobilityStatus', smartMobilityTypes: SmartMobilityType[], callback?: Callback<SmartMobilityInfo>): void
Unregisters a smart mobility connection status listener. This API uses an asynchronous callback to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.CarService.DistributedEngine
Device behavior differences: For 6.0.0(22) and earlier versions, this API is supported on phones. On other device types, it returns error code 801. For 6.1.0(23) and later versions, this API is supported on both phones and tablets, but does not respond on other device types.
Required permission: ohos.permission.ACCESS_CAR_DISTRIBUTED_ENGINE
Since: 5.0.0(12)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Subscription type. The value is a constant: smartMobilityStatus, which indicates unregistering a service connection status listener. |
| smartMobilityTypes | SmartMobilityType[] | Yes | Service type array, which can contain multiple services. |
| callback | Callback<SmartMobilityInfo> | No | Callback function to be unregistered, which must be the same as that passed upon subscription. If this parameter is not passed, all callback functions will be unregistered. |
Error codes:
For details about the error codes, please refer to Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed; 4. The size of specified type is greater than 255. |
| 801 | Capability not supported. |
Example:
import { smartMobilityCommon } from '@kit.CarKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
try {
// Obtain the SmartMobilityAwareness instance.
let awareness: smartMobilityCommon.SmartMobilityAwareness = smartMobilityCommon.getSmartMobilityAwareness();
// Service type.
let types: smartMobilityCommon.SmartMobilityType[] = [smartMobilityCommon.SmartMobilityType.HICAR];
// Mobility connection status callback function.
const callBack = (info: smartMobilityCommon.SmartMobilityInfo) => {
hilog.info(0x0000, 'testTag', 'Received smart mobility info: ', JSON.stringify(info));
};
// Unregister the smart mobility connection status listener.
awareness.off('smartMobilityStatus', types, callBack);
} catch (e) {
// Obtain the error code for an API call exception and handle the exception.
hilog.error(0x0000, 'testTag', `off smart mobility status error, error code: ${e?.code}`);
} getSmartMobilityStatus(type: SmartMobilityType): SmartMobilityInfo
Obtains the smart mobility connection status.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.CarService.DistributedEngine
Device behavior differences: For 6.0.0(22) and earlier versions, this API is supported on phones. On other device types, it returns error code 801. For 6.1.0(23) and later versions, this API is supported on both phones and tablets, but does not respond on other device types.
Required permission: ohos.permission.ACCESS_CAR_DISTRIBUTED_ENGINE
Since: 5.0.0(12)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| type | SmartMobilityType | Yes | Service type. |
Returns:
| Type | Description |
|---|---|
| SmartMobilityInfo | Service connection status information. |
Error codes:
For details about the error codes, please refer to Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed; 4. The size of specified type is greater than 255. |
| 801 | Capability not supported. |
Example:
import { smartMobilityCommon } from '@kit.CarKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
try {
// Obtain the SmartMobilityAwareness instance.
let awareness: smartMobilityCommon.SmartMobilityAwareness = smartMobilityCommon.getSmartMobilityAwareness();
// Service type.
let type = smartMobilityCommon.SmartMobilityType.HICAR;
// Obtain the service status information.
let ret = awareness.getSmartMobilityStatus(type);
hilog.info(0x0000, 'testTag', `get smart mobility status succeed, status: ${JSON.stringify(ret)}`);
} catch (e) {
// Obtain the error code for an API call exception and handle the exception.
hilog.error(0x0000, 'testTag', `get smart mobility status error, errCode: ${e?.code}`);
} Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
Quick start
Helps you find desired resources with ease.