@ohos.telephony.vcard (VCard)
VCard is a file format standard for electronic business cards. It contains information such as names, addresses, phone numbers, URLs, logos, and photos. The VCard module provides the VCard management functions, including importing VCard files to the contact database and exporting contact data to VCard files.
NOTE
The initial APIs of this module are supported since API version 23. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Modules to Import
import { vcard } from '@kit.TelephonyKit';
vcard.importVCard
importVCard(context: Context, filePath: string, accountId: number, callback: AsyncCallback<void>): void
Imports a VCard file (that is, .vcf file) to the contact database. This API uses an asynchronous callback to return the result.
Required permissions: ohos.permission.WRITE_CONTACTS and ohos.permission.READ_CONTACTS
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| context | Context | Yes | Application context. |
| filePath | string | Yes | URL of the vcard file (VCF). |
| accountId | number | Yes | Contact account ID. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. |
Error codes:
For details about the error codes, see Telephony Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 8300001 | Invalid parameter value. |
| 8300003 | System internal error. |
| 8300999 | Unknown error. |
Example:
import { window } from '@kit.ArkUI';
import { UIAbility } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { vcard } from '@kit.TelephonyKit';
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage: window.WindowStage) {
let filePath: string = "/data/storage/vcf/contacts.vcf";
let accountId: number = 0;
vcard.importVCard(this.context, filePath, accountId, (err: BusinessError) => {
console.error(`callback: err->${JSON.stringify(err)}`);
});
}
}
vcard.importVCard
importVCard(context: Context, filePath: string, accountId?: number): Promise<void>
Imports a VCard file (that is, .vcf file) to the contact database. This API uses a promise to return the result.
Required permissions: ohos.permission.WRITE_CONTACTS and ohos.permission.READ_CONTACTS
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| context | Context | Yes | Application context. |
| filePath | string | Yes | URL of the vcard file (VCF). |
| accountId | number | No | Contact account ID. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise used to return the operation result. |
Error codes:
For details about the error codes, see Telephony Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 8300001 | Invalid parameter value. |
| 8300003 | System internal error. |
| 8300999 | Unknown error. |
Example:
import { window } from '@kit.ArkUI';
import { UIAbility } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { vcard } from '@kit.TelephonyKit';
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage: window.WindowStage) {
let filePath: string = "/data/storage/vcf/contacts.vcf";
let accountId: number = 0;
vcard.importVCard(this.context, filePath, accountId).then(() => {
console.info(`importVCard success.`);
}).catch((err: BusinessError) => {
console.error(`importVCard failed, promise: err->${JSON.stringify(err)}`);
});
}
}
vcard.importVCard
importVCard(context: Context, filePath: string, callback: AsyncCallback<void>): void
Imports a VCard file (that is, .vcf file) to the contact database. This API uses an asynchronous callback to return the result.
Required permissions: ohos.permission.WRITE_CONTACTS and ohos.permission.READ_CONTACTS
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| context | Context | Yes | Application context. |
| filePath | string | Yes | URL of the vcard file (VCF). |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. |
Error codes:
For details about the error codes, see Telephony Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 8300001 | Invalid parameter value. |
| 8300003 | System internal error. |
| 8300999 | Unknown error. |
Example:
import { window } from '@kit.ArkUI';
import { UIAbility } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { vcard } from '@kit.TelephonyKit';
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage: window.WindowStage) {
let filePath: string = "/data/storage/vcf/contacts.vcf";
vcard.importVCard(this.context, filePath, (err: BusinessError) => {
console.error(`callback: err->${JSON.stringify(err)}`);
});
}
}
vcard.exportVCard
exportVCard(context: Context, predicates: dataSharePredicates.DataSharePredicates, options: VCardBuilderOptions, callback: AsyncCallback<string>): void
Exports contacts as a vcard file (VCF). This API uses an asynchronous callback to return the result.
Required permissions: ohos.permission.WRITE_CONTACTS and ohos.permission.READ_CONTACTS
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| context | Context | Yes | Application context. |
| predicates | dataSharePredicates.DataSharePredicates | Yes | Query statement. |
| options | VCardBuilderOptions | Yes | VCard version and encoding type. |
| callback | AsyncCallback<string> | Yes | Callback used to Address of the generated vcard file (VCF). |
Error codes:
For details about the error codes, see Telephony Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 8300001 | Invalid parameter value. |
| 8300003 | System internal error. |
| 8300999 | Unknown error. |
Example:
import { window } from '@kit.ArkUI';
import { UIAbility } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { vcard } from '@kit.TelephonyKit';
import { dataSharePredicates } from '@kit.ArkData';
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage: window.WindowStage) {
let predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo("NAME", "Rose");
let options: vcard.VCardBuilderOptions = {
cardType: vcard.VCardType.VERSION_21,
charset: "UTF-8"
};
vcard.exportVCard(this.context, predicates, options, (err: BusinessError, data: string) => {
console.error(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
}
}
vcard.exportVCard
exportVCard(context: Context, predicates: dataSharePredicates.DataSharePredicates, options?: VCardBuilderOptions): Promise<string>
Exports contacts as a vcard file (VCF). This API uses a promise to return the result.
Required permissions: ohos.permission.WRITE_CONTACTS and ohos.permission.READ_CONTACTS
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| context | Context | Yes | Application context. |
| predicates | dataSharePredicates.DataSharePredicates | Yes | Query statement. |
| options | VCardBuilderOptions | No | VCard version and encoding type. |
Return value
| Type | Description |
|---|---|
| Promise<string> | Promise used to return the operation result. |
Error codes:
For details about the error codes, see Telephony Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 8300001 | Invalid parameter value. |
| 8300003 | System internal error. |
| 8300999 | Unknown error. |
Example:
import { window } from '@kit.ArkUI';
import { UIAbility } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { vcard } from '@kit.TelephonyKit';
import { dataSharePredicates } from '@kit.ArkData';
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage: window.WindowStage) {
let predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo("NAME", "Rose");
let options: vcard.VCardBuilderOptions = {
cardType: vcard.VCardType.VERSION_21,
charset: "UTF-8"
};
vcard.exportVCard(this.context, predicates, options).then(() => {
console.info(`exportVCard success.`);
}).catch((err: BusinessError) => {
console.error(`exportVCard failed, promise: err->${JSON.stringify(err)}`);
});
}
}
vcard.exportVCard
exportVCard(context: Context, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback<string>): void
Exports contacts as a vcard file (VCF). This API uses an asynchronous callback to return the result.
Required permissions: ohos.permission.WRITE_CONTACTS and ohos.permission.READ_CONTACTS
System capability: SystemCapability.Telephony.CoreService
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| context | Context | Yes | Application context. |
| predicates | dataSharePredicates.DataSharePredicates | Yes | Query statement. |
| callback | AsyncCallback<string> | Yes | Callback used to Address of the generated vcard file (VCF). |
Error codes:
For details about the error codes, see Telephony Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 8300001 | Invalid parameter value. |
| 8300003 | System internal error. |
| 8300999 | Unknown error. |
Example:
import { window } from '@kit.ArkUI';
import { UIAbility } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { vcard } from '@kit.TelephonyKit';
import { dataSharePredicates } from '@kit.ArkData';
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage: window.WindowStage) {
let predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo("NAME", "Rose");
vcard.exportVCard(this.context, predicates, (err: BusinessError, data: string) => {
console.error(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
}
}
VCardBuilderOptions
Defines the VCard information.
System capability: SystemCapability.Telephony.CoreService
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| cardType | VCardType | No | Yes | VCard version. The default value is VERSION_21. |
| charset | string | No | Yes | VCard encoding type. The default value is UTF-8. |
VCardType
Enumerates VCard versions.
System capability: SystemCapability.Telephony.CoreService
| Name | Value | Description |
|---|---|---|
| VERSION_21 | 0 | VCard 2.1. |
| VERSION_30 | 1 | VCard 3.0. |
| VERSION_40 | 2 | VCard 4.0. |
你可能感兴趣的鸿蒙文章
openharmony 鸿蒙 js-apis-sms-sys
openharmony 鸿蒙 capi-telephony-radio-type-h
openharmony 鸿蒙 js-apis-sim-sys
openharmony 鸿蒙 js-apis-telephony-data-sys
openharmony 鸿蒙 js-apis-observer-sys
openharmony 鸿蒙 capi-telephony-data-h
openharmony 鸿蒙 ndk-apis-telephony-radio