harmony 鸿蒙@ohos.multimedia.systemSoundManager (System Sound Management) (System API)

  • 2025-06-12
  • 浏览 (5)

@ohos.multimedia.systemSoundManager (System Sound Management) (System API)

The systemSoundManager module provides basic capabilities for managing system sounds, including setting and obtaining ringtones and obtaining a player to play the ringtones.

NOTE

  • The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
  • The APIs provided by this module are system APIs.

Modules to Import

import { systemSoundManager } from '@kit.AudioKit';

Constants

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Name Value Description
TONE_CATEGORY_RINGTONE12+ 1 Ringtone.
TONE_CATEGORY_TEXT_MESSAGE12+ 2 SMS tone.
TONE_CATEGORY_NOTIFICATION12+ 4 Notification tone.
TONE_CATEGORY_ALARM12+ 8 Alarm tone.

RingtoneType

Enumerates the ringtone types.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Name Value Description
RINGTONE_TYPE_DEFAULT(deprecated) 0 Default ringtone type.
This enumerated value is deprecated since API version 11. You are advised to use RINGTONE_TYPE_SIM_CARD_0 instead.
RINGTONE_TYPE_SIM_CARD_011+ 0 Ringtone of SIM card 1.
RINGTONE_TYPE_MULTISIM(deprecated) 1 Multi-SIM ringtone type.
This enumerated value is deprecated since API version 11. You are advised to use RINGTONE_TYPE_SIM_CARD_1 instead.
RINGTONE_TYPE_SIM_CARD_111+ 1 Ringtone of SIM card 2.

SystemToneType11+

Enumerates the system tone types.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Name Value Description
SYSTEM_TONE_TYPE_SIM_CARD_0 0 SMS tone of SIM card 1.
SYSTEM_TONE_TYPE_SIM_CARD_1 1 SMS tone of SIM card 2.
SYSTEM_TONE_TYPE_NOTIFICATION 32 Notification tone.

ToneCustomizedType12+

Enumerates the tone customization types.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Name Value Description
PRE_INSTALLED12+ 0 Preinstalled tone.
CUSTOMIZED12+ 1 Custom tone.

ToneAttrs12+

Manages tone attributes. Before calling any API in ToneAttrs12+, you must use createCustomizedToneAttrs, getDefaultRingtoneAttrs, or getRingtoneAttrList to obtain a tone instance.

getTitle12+

getTitle(): string

Obtains the title of this tone.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Return value

Type Description
string Title.

Error codes

ID Error Message
202 Caller is not a system application.

Example

toneAttrs.getTitle();

setTitle12+

setTitle(title: string): void

Sets the title for this tone.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
title string Yes Title.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
202 Caller is not a system application.
401 The parameters check failed.

Example

let toneAttrs = systemSoundManager.createCustomizedToneAttrs();
let title = 'text';
toneAttrs.setTitle(title);

getFileName12+

getFileName(): string

Obtains the file name of this tone.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Return value

Type Description
string File name.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
202 Caller is not a system application.

Example

toneAttrs.getFileName();

setFileName12+

setFileName(name: string): void

Sets the file name for this tone.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
name string Yes File name.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
202 Caller is not a system application.
401 The parameters check failed.

Example

let toneAttrs = systemSoundManager.createCustomizedToneAttrs();
let fileName = 'textFileName';
toneAttrs.setFileName(fileName);

getUri12+

getUri(): string

Obtains the URI of this tone.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Return value

Type Description
string URI, for example, ’/data/storage/el2/base/RingTone/alarms/test.ogg’.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
202 Caller is not a system application.

Example

toneAttrs.getUri();

getCustomizedType12+

getCustomizedType(): string

Obtains the tone customization type.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Return value

Type Description
ToneCustomizedType Tone customization type.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
202 Caller is not a system application.

Example

toneAttrs.getCustomizedType();

setCategory12+

setCategory(category: number): void

Sets a category for this tone.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
category number Yes Category of the tone. For details, see Constants.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
202 Caller is not a system application.
401 The parameters check failed.

Example

let toneAttrs = systemSoundManager.createCustomizedToneAttrs();
let categoryValue = systemSoundManager.TONE_CATEGORY_ALARM; // Change the value to the required constant.
toneAttrs.setCategory(categoryValue);

getCategory12+

getCategory(): string

Obtains the category of this tone.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Return value

Type Description
number Category of the tone. For details, see Constants.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
202 Caller is not a system application.

Example

toneAttrs.getCategory();

ToneAttrsArray12+

type ToneAttrsArray = Array<ToneAttrs>

Defines an array of tone attributes.

System capability: SystemCapability.Multimedia.SystemSound.Core

Type Description
Array<ToneAttrs> Array of tone attributes.

systemSoundManager.createCustomizedToneAttrs12+

createCustomizedToneAttrs(): ToneAttrs

Creates customized tone attributes.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Return value

Type Description
ToneAttrs Class for tone attributes.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
202 Caller is not a system application.

Example

let toneAttrs: systemSoundManager.ToneAttrs = systemSoundManager.createCustomizedToneAttrs();

ToneHapticsFeature13+

Enumerates the haptics styles for different tones.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

|Name |Value|Description | |—————————–|–|——————–| |STANDARD|0|Standard haptics style.| |GENTLE |1|Gentle haptics style.|

ToneHapticsType14+

Enumerates the haptics types for different tones.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Name Value Description
CALL_SIM_CARD_0 0 Haptic feedback for ringtone on SIM card 1.
CALL_SIM_CARD_1 1 Haptic feedback for ringtone on SIM card 2.
TEXT_MESSAGE_SIM_CARD_0 20 Haptic feedback for SMS tone on SIM card 1.
TEXT_MESSAGE_SIM_CARD_1 21 Haptic feedback for SMS tone on SIM card 2.
NOTIFICATION 40 Haptic feedback for notification tone.

ToneHapticsMode14+

Enumerates the haptics modes in tone playback scenarios.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

|Name |Value|Description | |—————————–|–|——————–| |NONE |0|No haptics.| |SYNC |1|Sync mode, where haptic feedback is aligned with tone playback.| |NON_SYNC |2|Non-sync mode, where haptic feedback is not aligned with tone playback.|

ToneHapticsSettings14+

Describes the haptics settings of a tone.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

|Name |Type|Read-Only|Optional|Description | |————|–|–|–|——————–| |mode|ToneHapticsMode|No|No|Haptics mode.| |hapticsUri|string |No|Yes|URI of the haptics resource. The URI, obtained by calling getToneHapticsList, is valid only in the non-sync mode and should be ignored in other haptics modes.|

ToneHapticsAttrs14+

Manages haptics attributes of tones. Before calling any API in ToneHapticsAttrs14+, you must call getToneHapticsList or getHapticsAttrsSyncedWithTone to obtain an instance.

getUri14+

getUri(): string

Obtains the URI of this haptics resource.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Return value

Type Description
string URI, for example, ’/data/storage/el2/base/haptics/synchronized/alarms/test.json’.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
202 Caller is not a system application.

Example

toneHapticsAttrs.getUri();

getTitle14+

getTitle(): string

Obtains the title of this haptics resource.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Return value

Type Description
string Title.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
202 Caller is not a system application.

Example

toneHapticsAttrs.getTitle();

getFileName14+

getFileName(): string

Obtains the file name of this haptics resource.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Return value

Type Description
string File name.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
202 Caller is not a system application.

Example

toneHapticsAttrs.getFileName();

ToneHapticsAttrsArray14+

type ToneHapticsAttrsArray = Array<ToneHapticsAttrs>

Describes the haptics attribute array of a tone.

System capability: SystemCapability.Multimedia.SystemSound.Core

Type Description
Array<ToneHapticsAttrs> Array of haptics attributes.

systemSoundManager.getSystemSoundManager

getSystemSoundManager(): SystemSoundManager

Obtains a system sound manager.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Return value

Type Description
SystemSoundManager System sound manager obtained.

Example

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();

SystemSoundManager

Provides APIs to manage system sounds. Before calling any API in SystemSoundManager, you must use getSystemSoundManager to create a SystemSoundManager instance.

setSystemRingtoneUri(deprecated)

setSystemRingtoneUri(context: Context, uri: string, type: RingtoneType, callback: AsyncCallback<void>): void

Sets a URI for a ringtone. This API uses an asynchronous callback to return the result.

NOTE

This API is supported since API version 10 and deprecated since API version 11. You are advised to use setRingtoneUri instead.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
context Context Yes Application context.
uri string Yes URI of the ringtone. For details about supported resources, see media.AVPlayer.
type RingtoneType Yes Type of the ringtone.
callback AsyncCallback<void> Yes Callback used to return the result. If the operation is successful, err is undefined; otherwise, err is an error object.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let uri = 'file://data/test.wav'; // Set the URI of the target tone file.
let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_DEFAULT;

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
systemSoundManagerInstance.setSystemRingtoneUri(context, uri, type, (err: BusinessError) => {
  if (err) {
    console.error(`Failed to set system ringtone uri. ${err}`);
    return;
  }
  console.info(`Callback invoked to indicate a successful setting of the system ringtone uri.`);
});

setSystemRingtoneUri(deprecated)

setSystemRingtoneUri(context: Context, uri: string, type: RingtoneType): Promise<void>

Sets a URI for a ringtone. This API uses a promise to return the result.

NOTE

This API is supported since API version 10 and deprecated since API version 11. You are advised to use setRingtoneUri instead.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
context Context Yes Application context.
uri string Yes URI of the ringtone. For details about supported resources, see media.AVPlayer.
type RingtoneType Yes Type of the ringtone.

Return value

Type Description
Promise<void> Promise that returns no value.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let uri = 'file://data/test.wav'; // Set the URI of the target tone file.
let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_DEFAULT;

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
systemSoundManagerInstance.setSystemRingtoneUri(context, uri, type).then(() => {
  console.info(`Promise returned to indicate a successful setting of the system ringtone uri.`);
}).catch ((err: BusinessError) => {
  console.error(`Failed to set the system ringtone uri ${err}`);
});

getSystemRingtoneUri(deprecated)

getSystemRingtoneUri(context: Context, type: RingtoneType, callback: AsyncCallback<string>): void

Obtains the URI of a ringtone. This API uses an asynchronous callback to return the result.

NOTE

This API is supported since API version 10 and deprecated since API version 11. You are advised to use getRingtoneUri instead.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
context Context Yes Application context.
type RingtoneType Yes Type of the ringtone.
callback AsyncCallback<string> Yes Callback used to return the result. If the operation is successful, err is undefined and data is the URI obtained; otherwise, err is an error object.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_DEFAULT;

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
systemSoundManagerInstance.getSystemRingtoneUri(context, type, (err: BusinessError, value: string) => {
  if (err) {
    console.error(`Failed to get system ringtone uri. ${err}`);
    return;
  }
  console.info(`Callback invoked to indicate the value of the system ringtone uri is obtained ${value}.`);
});

getSystemRingtoneUri(deprecated)

getSystemRingtoneUri(context: Context, type: RingtoneType): Promise<string>

Obtains the URI of a ringtone. This API uses a promise to return the result.

NOTE

This API is supported since API version 10 and deprecated since API version 11. You are advised to use getRingtoneUri instead.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
context Context Yes Application context.
type RingtoneType Yes Type of the ringtone.

Return value

Type Description
Promise<string> Promise used to return the URI obtained.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_DEFAULT;

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
systemSoundManagerInstance.getSystemRingtoneUri(context, type).then((value: string) => {
  console.info(`Promise returned to indicate that the value of the system ringtone uri is obtained ${value}.`);
}).catch ((err: BusinessError) => {
  console.error(`Failed to get the system ringtone uri ${err}`);
});

getSystemRingtonePlayer(deprecated)

getSystemRingtonePlayer(context: Context, type: RingtoneType, callback: AsyncCallback<RingtonePlayer>): void

Obtains a player to play a ringtone. This API uses an asynchronous callback to return the result.

NOTE

This API is supported since API version 10 and deprecated since API version 11. You are advised to use getRingtonePlayer instead.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
context Context Yes Application context.
type RingtoneType Yes Type of the ringtone.
callback AsyncCallback<RingtonePlayer> Yes Callback used to return the result. If the operation is successful, err is undefined and data is the player obtained; otherwise, err is an error object.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_DEFAULT;
let systemRingtonePlayer: systemSoundManager.RingtonePlayer|undefined = undefined;

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
systemSoundManagerInstance.getSystemRingtonePlayer(context, type, (err: BusinessError, value: systemSoundManager.RingtonePlayer) => {
  if (err) {
    console.error(`Failed to get system ringtone player. ${err}`);
    return;
  }
  console.info(`Callback invoked to indicate the value of the system ringtone player is obtained.`);
  systemRingtonePlayer = value;
});

getSystemRingtonePlayer(deprecated)

getSystemRingtonePlayer(context: Context, type: RingtoneType): Promise<RingtonePlayer>

Obtains a player to play a ringtone. This API uses a promise to return the result.

NOTE

This API is supported since API version 10 and deprecated since API version 11. You are advised to use getRingtonePlayer instead.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
context Context Yes Application context.
type RingtoneType Yes Type of the ringtone.

Return value

Type Description
Promise<RingtonePlayer> Promise used to return the player obtained.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_DEFAULT;
let systemRingtonePlayer: systemSoundManager.RingtonePlayer|undefined = undefined;

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
systemSoundManagerInstance.getSystemRingtonePlayer(context, type).then((value: systemSoundManager.RingtonePlayer) => {
  console.info(`Promise returned to indicate that the value of the system ringtone player is obtained.`);
  systemRingtonePlayer = value;
}).catch ((err: BusinessError) => {
  console.error(`Failed to get the system ringtone player ${err}`);
});

setRingtoneUri11+

setRingtoneUri(context: BaseContext, uri: string, type: RingtoneType): Promise<void>

Sets a URI for a ringtone. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
context BaseContext Yes Application context.
uri string Yes URI of the ringtone. For details about supported resources, see media.AVPlayer.
type RingtoneType Yes Type of the ringtone.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Media Error Codes.

ID Error Message
202 Caller is not a system application.
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.
5400103 I/O error.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let uri = 'file://data/test.wav'; // Set the URI of the target tone file.
let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_SIM_CARD_0;

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
systemSoundManagerInstance.setRingtoneUri(context, uri, type).then(() => {
  console.info(`Promise returned to indicate a successful setting of the system ringtone uri.`);
}).catch ((err: BusinessError) => {
  console.error(`Failed to set the system ringtone uri ${err}`);
});

getRingtoneUri11+

getRingtoneUri(context: BaseContext, type: RingtoneType): Promise<string>

Obtains the URI of a ringtone. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
context BaseContext Yes Application context.
type RingtoneType Yes Type of the ringtone.

Return value

Type Description
Promise<string> Promise used to return the URI obtained.

Error codes

For details about the error codes, see Universal Error Codes and Media Error Codes.

ID Error Message
202 Caller is not a system application.
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.
5400103 I/O error.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_SIM_CARD_0;

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
systemSoundManagerInstance.getRingtoneUri(context, type).then((value: string) => {
  console.info(`Promise returned to indicate that the value of the system ringtone uri is obtained ${value}.`);
}).catch ((err: BusinessError) => {
  console.error(`Failed to get the system ringtone uri ${err}`);
});

getRingtonePlayer11+

getRingtonePlayer(context: BaseContext, type: RingtoneType): Promise<RingtonePlayer>

Obtains a player to play a ringtone. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
context BaseContext Yes Application context.
type RingtoneType Yes Type of the ringtone.

Return value

Type Description
Promise<RingtonePlayer> Promise used to return the player obtained.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
202 Caller is not a system application.
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_SIM_CARD_0;
let systemRingtonePlayer: systemSoundManager.RingtonePlayer|undefined = undefined;

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
systemSoundManagerInstance.getRingtonePlayer(context, type).then((value: systemSoundManager.RingtonePlayer) => {
  console.info(`Promise returned to indicate that the value of the system ringtone player is obtained.`);
  systemRingtonePlayer = value;
}).catch ((err: BusinessError) => {
  console.error(`Failed to get the system ringtone player ${err}`);
});

setSystemToneUri11+

setSystemToneUri(context: BaseContext, uri: string, type: SystemToneType): Promise<void>

Sets a URI for a system tone. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
context BaseContext Yes Application context.
uri string Yes URI of the system tone. For details about supported resources, see media.AVPlayer.
type SystemToneType Yes Type of the system tone.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Media Error Codes.

ID Error Message
202 Caller is not a system application.
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.
5400103 I/O error.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let uri = 'file://data/test.wav'; // Set the URI of the target tone file.
let type: systemSoundManager.SystemToneType = systemSoundManager.SystemToneType.SYSTEM_TONE_TYPE_SIM_CARD_0;

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
systemSoundManagerInstance.setSystemToneUri(context, uri, type).then(() => {
  console.info(`Promise returned to indicate a successful setting of the system tone uri.`);
}).catch ((err: BusinessError) => {
  console.error(`Failed to set the system tone uri ${err}`);
});

getSystemToneUri11+

getSystemToneUri(context: BaseContext, type: SystemToneType): Promise<string>

Obtains the URI of a system tone. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
context BaseContext Yes Application context.
type SystemToneType Yes Type of the system tone.

Return value

Type Description
Promise<string> Promise used to return the URI obtained.

Error codes

For details about the error codes, see Universal Error Codes and Media Error Codes.

ID Error Message
202 Caller is not a system application.
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.
5400103 I/O error.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let type: systemSoundManager.SystemToneType = systemSoundManager.SystemToneType.SYSTEM_TONE_TYPE_SIM_CARD_0;

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
systemSoundManagerInstance.getSystemToneUri(context, type).then((value: string) => {
  console.info(`Promise returned to indicate that the value of the system tone uri is obtained ${value}.`);
}).catch ((err: BusinessError) => {
  console.error(`Failed to get the system tone uri ${err}`);
});

getSystemTonePlayer11+

getSystemTonePlayer(context: BaseContext, type: SystemToneType): Promise<SystemTonePlayer>

Obtains a player to play a system tone. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
context BaseContext Yes Application context.
type SystemToneType Yes Type of the system tone.

Return value

Type Description
Promise<SystemTonePlayer> Promise used to return the player obtained.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
202 Caller is not a system application.
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let type: systemSoundManager.SystemToneType = systemSoundManager.SystemToneType.SYSTEM_TONE_TYPE_SIM_CARD_0;
let systemTonePlayer: systemSoundManager.SystemTonePlayer|undefined = undefined;

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
systemSoundManagerInstance.getSystemTonePlayer(context, type).then((value: systemSoundManager.SystemTonePlayer) => {
  console.info(`Promise returned to indicate that the value of the system tone player is obtained.`);
    systemTonePlayer = value;
}).catch ((err: BusinessError) => {
  console.error(`Failed to get the system tone player ${err}`);
});

getDefaultRingtoneAttrs12+

getDefaultRingtoneAttrs(context: BaseContext, type: RingtoneType): Promise<ToneAttrs>

Obtains the attributes of the default ringtone. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
context BaseContext Yes Application context.
type RingtoneType Yes Type of the ringtone.

Return value

Type Description
Promise<ToneAttrs> Promise used to return the attributes of the default ringtone.

Error codes

For details about the error codes, see Universal Error Codes and Media Error Codes.

ID Error Message
202 Caller is not a system application.
401 The parameters check failed.
5400103 I/O error.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_SIM_CARD_0;

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
systemSoundManagerInstance.getDefaultRingtoneAttrs(context, type).then((value: systemSoundManager.ToneAttrs) => {
  console.info(`Promise returned to indicate that the value of the attributes of the default ringtone is obtained.`);
}).catch ((err: BusinessError) => {
  console.error(`Failed to get the default ring tone attrs ${err}`);
});

getRingtoneAttrList12+

getRingtoneAttrList(context: BaseContext, type: RingtoneType): Promise<ToneAttrsArray>

Obtains an array of attributes of ringtones. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
context BaseContext Yes Application context.
type RingtoneType Yes Type of the ringtone.

Return value

Type Description
Promise<ToneAttrsArray> Promise used to return an array of the attributes of ringtones.

Error codes

For details about the error codes, see Universal Error Codes and Media Error Codes.

ID Error Message
202 Caller is not a system application.
401 The parameters check failed.
5400103 I/O error.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_SIM_CARD_0;

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
systemSoundManagerInstance.getRingtoneAttrList(context, type).then((value: systemSoundManager.ToneAttrsArray) => {
  console.info(`Promise returned to indicate that the value of the attribute list of ringtone is obtained.`);
}).catch ((err: BusinessError) => {
  console.error(`Failed to get the attribute list of ringtone ${err}`);
});

getDefaultSystemToneAttrs12+

getDefaultSystemToneAttrs(context: BaseContext, type: SystemToneType): Promise<ToneAttrs>

Obtains the attributes of the default system tone. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
context BaseContext Yes Application context.
type SystemToneType Yes Type of the system tone.

Return value

Type Description
Promise<ToneAttrs> Promise used to return the attributes of the default system tone.

Error codes

For details about the error codes, see Universal Error Codes and Media Error Codes.

ID Error Message
202 Caller is not a system application.
401 The parameters check failed.
5400103 I/O error.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let type: systemSoundManager.SystemToneType = systemSoundManager.SystemToneType.SYSTEM_TONE_TYPE_SIM_CARD_0;

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
systemSoundManagerInstance.getDefaultSystemToneAttrs(context, type).then((value: systemSoundManager.ToneAttrs) => {
  console.info(`Promise returned to indicate that the value of the attributes of the system ringtone is obtained.`);
}).catch ((err: BusinessError) => {
  console.error(`Failed to get the system tone attrs ${err}`);
});

getSystemToneAttrList12+

getSystemToneAttrList(context: BaseContext, type: SystemToneType): Promise<ToneAttrsArray>

Obtains an array of attributes of system tones. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
context BaseContext Yes Application context.
type SystemToneType Yes Type of the system tone.

Return value

Type Description
Promise<ToneAttrsArray> Promise used to return an array of the attributes of system tones.

Error codes

For details about the error codes, see Universal Error Codes and Media Error Codes.

ID Error Message
202 Caller is not a system application.
401 The parameters check failed.
5400103 I/O error.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let type: systemSoundManager.SystemToneType = systemSoundManager.SystemToneType.SYSTEM_TONE_TYPE_SIM_CARD_0;

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
systemSoundManagerInstance.getSystemToneAttrList(context, type).then((value: systemSoundManager.ToneAttrsArray) => {
  console.info(`Promise returned to indicate that the value of the attribute list of system tone is obtained.`);
}).catch ((err: BusinessError) => {
  console.error(`Failed to get the attribute list of system tone ${err}`);
});

getDefaultAlarmToneAttrs12+

getDefaultAlarmToneAttrs(context: BaseContext): Promise<ToneAttrs>

Obtains the attributes of the default alarm tone. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
context BaseContext Yes Application context.

Return value

Type Description
Promise<ToneAttrs> Promise used to return the attributes of the default alarm tone.

Error codes

For details about the error codes, see Universal Error Codes and Media Error Codes.

ID Error Message
202 Caller is not a system application.
401 The parameters check failed.
5400103 I/O error.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
systemSoundManagerInstance.getDefaultAlarmToneAttrs(context).then((value: systemSoundManager.ToneAttrs) => {
  console.info(`Promise returned to indicate that the value of the attributes of the default alarm tone is obtained.`);
}).catch ((err: BusinessError) => {
  console.error(`Failed to get the default alarm tone attrs ${err}`);
});

setAlarmToneUri12+

setAlarmToneUri(context: Context, uri: string): Promise<void>

Sets a URI for an alarm tone. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
context Context Yes Application context.
uri string Yes URI of the alarm tone. For details about supported resources, see media.AVPlayer.

Return value

Type Description
Promise<void> Promise that returns no value.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let uri = 'file://data/test.wav'; // Set the URI of the target tone file.

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
systemSoundManagerInstance.setAlarmToneUri(context, uri).then(() => {
  console.info(`Promise returned to indicate a successful setting of the alarm tone uri.`);
}).catch ((err: BusinessError) => {
  console.error(`Failed to set the alarm tone uri ${err}`);
});

getAlarmToneUri12+

getAlarmToneUri(context: Context): Promise<string>

Obtains the URI of the current alarm tone. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
context Context Yes Application context.

Return value

Type Description
Promise<string> Promise used to return the URI of the current alarm tone.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
systemSoundManagerInstance.getAlarmToneUri(context).then((value: string) => {
  console.info(`Promise returned to indicate that the value of alarm tone uri.`);
}).catch ((err: BusinessError) => {
  console.error(`Failed to get the alarm tone uri ${err}`);
});

getAlarmToneAttrList12+

getAlarmToneAttrList(context: BaseContext): Promise<ToneAttrsArray>

Obtains an array of attributes of alarm tones. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
context BaseContext Yes Application context.

Return value

Type Description
Promise<ToneAttrsArray> Promise used to return an array of the attributes of alarm tones.

Error codes

For details about the error codes, see Universal Error Codes and Media Error Codes.

ID Error Message
202 Caller is not a system application.
401 The parameters check failed.
5400103 I/O error.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
systemSoundManagerInstance.getAlarmToneAttrList(context).then((value: systemSoundManager.ToneAttrsArray) => {
  console.info(`Promise returned to indicate that the value of the attribute list of alarm tone is obtained.`);
}).catch ((err: BusinessError) => {
  console.error(`Failed to get the attribute list of alarm tone ${err}`);
});

openAlarmTone12+

openAlarmTone(context: Context, uri: string): Promise<number>

Enables an alarm tone. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
context Context Yes Application context.
uri string Yes URI of the alarm tone. For details about supported resources, see media.AVPlayer.

Return value

Type Description
Promise<number> Promise used to return the FD.

Error codes

For details about the error codes, see Universal Error Codes and Media Error Codes.

ID Error Message
202 Caller is not a system application.
401 The parameters check failed.
5400103 I/O error.
20700001 Tone type mismatch, e.g. tone of uri is notification instead of alarm.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let uri = 'file://data/test.wav'; // Set the URI of the target tone file.

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
systemSoundManagerInstance.openAlarmTone(context, uri).then((value: number) => {
  console.info(`Promise returned to indicate the value of fd.`);
}).catch ((err: BusinessError) => {
  console.error(`Failed to open alarm tone ${err}`);
});

close12+

close(fd: number): Promise<void>

Disables an alarm tone. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
fd number Yes File descriptor, which is obtained through openAlarmTone.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Media Error Codes.

ID Error Message
202 Caller is not a system application.
401 The parameters check failed.
5400103 I/O error.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let fd = 50; // Use the FD of the target alarm tone.

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
systemSoundManagerInstance.close(fd).then(() => {
  console.info(`Promise returned to indicate that the fd has been close.`);
}).catch ((err: BusinessError) => {
  console.error(`Failed to close fd ${err}`);
});

addCustomizedTone12+

addCustomizedTone(context: BaseContext, toneAttr: ToneAttrs, externalUri: string): Promise<string>

Adds a custom tone with a given URI to the tone library. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
context Context Yes Application context.
toneAttr ToneAttrs Yes Attributes of the tone.
externalUri string Yes URI of the tone in the external storage device.

Return value

Type Description
Promise<string> Promise used to return the URI of the tone in the tone library.

Error codes

For details about the error codes, see Universal Error Codes and Media Error Codes.

ID Error Message
201 Permission denied.
202 Caller is not a system application.
401 The parameters check failed.
5400102 Operation is not allowed, e.g. ringtone to add is not customized.
5400103 I/O error.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let title = 'test'; // Set the title of the target tone.
let fileName = 'displayName_test'; // Set the file name of the target tone.
let categoryValue = systemSoundManager.TONE_CATEGORY_ALARM;

let toneAttrs = systemSoundManager.createCustomizedToneAttrs();
toneAttrs.setTitle(title);
toneAttrs.setFileName(fileName);
toneAttrs.setCategory(categoryValue);

let path = 'file://data/test.ogg'; // Set the URI of the target tone.

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
systemSoundManagerInstance.addCustomizedTone(context, toneAttrs, path).then((value: string) => {
  console.info(`Promise returned to indicate that the value of tone uri in ringtone library.`);
}).catch ((err: BusinessError) => {
  console.error(`Failed to add customized tone ${err}`);
});

addCustomizedTone12+

addCustomizedTone(context: BaseContext, toneAttr: ToneAttrs, fd: number, offset?: number, length?: number): Promise<string>

Adds a custom tone with a given FD to the tone library. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
context Context Yes Application context.
toneAttr ToneAttrs Yes Attributes of the tone.
fd number Yes File descriptor, which is obtained by calling fs.open.
offset number No Offset from which the data is read, in bytes. The default value is 0.
length number No Length of the data to read, in bytes. By default, the length is the total number of remaining bytes after the offset.

Return value

Type Description
Promise<string> Promise used to return the URI of the tone in the tone library.

Error codes

For details about the error codes, see Universal Error Codes and Media Error Codes.

ID Error Message
201 Permission denied.
202 Caller is not a system application.
401 The parameters check failed.
5400102 Operation is not allowed, e.g. ringtone to add is not customized.
5400103 I/O error.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let title = 'test'; // Set the title of the target tone.
let fileName = 'displayName_test'; // Set the file name of the target tone.
let categoryValue = systemSoundManager.TONE_CATEGORY_ALARM;

let toneAttrs = systemSoundManager.createCustomizedToneAttrs();
toneAttrs.setTitle(title);
toneAttrs.setFileName(fileName);
toneAttrs.setCategory(categoryValue);

let fd = 10; // Set the FD of the target tone.
let offset = 0; // Set the offset.
let length = 50; // Set the data length.

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
systemSoundManagerInstance.addCustomizedTone(context, toneAttrs, fd, offset, length).then((value: string) => {
  console.info(`Promise returned to indicate that the value of tone uri in ringtone library.`);
}).catch ((err: BusinessError) => {
  console.error(`Failed to add customized tone ${err}`);
});

removeCustomizedTone12+

removeCustomizedTone(context: BaseContext, uri: string): Promise<void>

Removes a custom tone from the tone library. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
context Context Yes Application context.
uri string Yes Tone URI, which is obtained by using addCustomizedTone or getAlarmToneAttrList.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Media Error Codes.

ID Error Message
201 Permission denied.
202 Caller is not a system application.
401 The parameters check failed.
5400102 Operation is not allowed, e.g. ringtone to add is not customized.
5400103 I/O error.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let uri = 'file://data/test.wav'; // Set the URI of the target tone file.

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
systemSoundManagerInstance.removeCustomizedTone(context, uri).then(() => {
  console.info(`Promise returned to indicate that the customized tone has been deleted.`);
}).catch ((err: BusinessError) => {
  console.error(`Failed to delete customized tone ${err}`);
});

getToneHapticsSettings14+

getToneHapticsSettings(context: BaseContext, type: ToneHapticsType): Promise<ToneHapticsSettings>

Obtains the haptics settings of the tone. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
context Context Yes Application context.
type ToneHapticsType Yes Haptics type of the tone.

Return value

Type Description
Promise<ToneHapticsSettings> Promise used to return the haptics settings.

Error codes

For details about the error codes, see Universal Error Codes and Media Error Codes.

ID Error Message
202 Caller is not a system application.
401 The parameters check failed.
5400103 I/O error.
20700003 Unsupported operation.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let type: systemSoundManager.ToneHapticsType = systemSoundManager.ToneHapticsType.CALL_SIM_CARD_0;

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
systemSoundManagerInstance.getToneHapticsSettings(context, type).then((value: systemSoundManager.ToneHapticsSettings) => {
  console.info(`Promise returned to indicate that the value of the tone haptics settings is obtained.`);
}).catch ((err: BusinessError) => {
  console.error(`Failed to get the tone haptics settings ${err}`);
});

setToneHapticsSettings14+

setToneHapticsSettings(context: BaseContext, type: ToneHapticsType, settings: ToneHapticsSettings): Promise<void>

Sets the haptics settings for the tone. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
context Context Yes Application context.
type ToneHapticsType Yes Haptics type of the tone.
settings ToneHapticsSettings Yes Haptics settings of the tone.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Media Error Codes.

ID Error Message
202 Caller is not a system application.
401 The parameters check failed.
5400102 Operation is not allowed, e.g. ringtone to add is not customized.
5400103 I/O error.
20700003 Unsupported operation.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let type: systemSoundManager.ToneHapticsType = systemSoundManager.ToneHapticsType.CALL_SIM_CARD_0;
let toneHapticsSettings: systemSoundManager.ToneHapticsSettings = {
  mode: systemSoundManager.ToneHapticsMode.NON_SYNC,
  hapticsUri: '/data/storage/el2/base/haptics/synchronized/alarms/test.json', // Use the URI obtained through getToneHapticsList.
}

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
systemSoundManagerInstance.setToneHapticsSettings(context, type, toneHapticsSettings).then(() => {
  console.info(`Promise returned to indicate a successful setting of the tone haptics.`);
}).catch ((err: BusinessError) => {
  console.error(`Failed to set the tone haptics settings ${err}`);
});

getToneHapticsList14+

getToneHapticsList(context: BaseContext, isSynced: boolean): Promise<ToneHapticsAttrsArray>

Obtains the haptics attributes of the tone in sync or non-sync mode. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
context Context Yes Application context.
isSynced boolean Yes Whether the haptics feedback is synchronized with the tone. The value true means that the haptics feedback is synchronized with the tone, and false means the opposite.

Return value

Type Description
Promise<ToneHapticsAttrsArray> Promise used to return the haptics attributes.

Error codes

For details about the error codes, see Universal Error Codes and Media Error Codes.

ID Error Message
202 Caller is not a system application.
401 The parameters check failed.
5400103 I/O error.
20700003 Unsupported operation.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
systemSoundManagerInstance.getToneHapticsList(context, false).then((value: systemSoundManager.ToneHapticsAttrsArray) => {
  console.info(`Promise returned to indicate that the value of the attribute list of tone haptics is obtained.`);
}).catch ((err: BusinessError) => {
  console.error(`Failed to get the attribute list of tone haptics ${err}`);
});

getHapticsAttrsSyncedWithTone14+

getHapticsAttrsSyncedWithTone(context: BaseContext, toneUri: string): Promise<ToneHapticsAttrs>

Obtains the attributes of the haptics feedback synchronized with the tone. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
context Context Yes Application context.
toneUri string Yes URI of the tone. The URI can be obtained by calling getRingtoneAttrList or getSystemToneAttrList.

Return value

Type Description
Promise<ToneHapticsAttrs> Promise used to return the haptics attributes.

Error codes

For details about the error codes, see Universal Error Codes and Media Error Codes.

ID Error Message
202 Caller is not a system application.
401 The parameters check failed.
5400102 Operation is not allowed, e.g. ringtone to add is not customized.
5400103 I/O error.
20700003 Unsupported operation.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let toneUri: string = '/data/storage/el2/base/RingTone/alarms/test.ogg'; // Use the actual URI of the ringtone.

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
systemSoundManagerInstance.getHapticsAttrsSyncedWithTone(context, toneUri).then((value: systemSoundManager.ToneHapticsAttrs) => {
  console.info(`Promise returned to indicate that the value of the attribute of tone haptics is obtained.`);
}).catch ((err: BusinessError) => {
  console.error(`Failed to get the attribute of tone haptics ${err}`);
});

openToneHaptics14+

openToneHaptics(context: Context, hapticsUri: string): Promise<number>

Enables haptics for the tone. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

Name Type Mandatory Description
context Context Yes Application context.
hapticsUri string Yes URI of the haptics resource. For details about supported resources, see media.AVPlayer.

Return value

Type Description
Promise<number> Promise used to return the FD.

Error codes

For details about the error codes, see Universal Error Codes and Media Error Codes.

ID Error Message
202 Caller is not a system application.
401 The parameters check failed.
5400102 Operation is not allowed, e.g. ringtone to add is not customized.
5400103 I/O error.
20700003 Unsupported operation.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';

// Obtain the context from the component and ensure that the return value of this.getUIContext().getHostContext() is UIAbilityContext.
let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
let hapticsUri = '/data/storage/el2/base/haptics/synchronized/alarms/test.json'; // Use the actual URI of the haptics resource.

let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
systemSoundManagerInstance.openToneHaptics(context, hapticsUri).then((value: number) => {
  console.info(`Promise returned to indicate the value of fd.`);
}).catch ((err: BusinessError) => {
  console.error(`Failed to open haptics ${err}`);
});

RingtonePlayer10+

type RingtonePlayer = _RingtonePlayer;

Defines a ringtone player.

System capability: SystemCapability.Multimedia.SystemSound.Core

Type Description
_RingtonePlayer Ringtone player.

SystemTonePlayer11+

type SystemTonePlayer = _SystemTonePlayer;

Defines a system tone player.

System capability: SystemCapability.Multimedia.SystemSound.Core

Type Description
_SystemTonePlayer System tone player.

RingtoneOptions10+

type RingtoneOptions = _RingtoneOptions;

Defines the configuration of a ringtone player.

System capability: SystemCapability.Multimedia.SystemSound.Core

Type Description
_RingtoneOptions Configuration of a ringtone player.

SystemToneOptions11+

type SystemToneOptions = _SystemToneOptions;

Defines the configuration of a system tone player.

System capability: SystemCapability.Multimedia.SystemSound.Core

Type Description
_SystemToneOptions Configuration of a system tone player.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Audio Kit

harmony 鸿蒙OH_AudioCapturer_Callbacks_Struct

harmony 鸿蒙OH_AudioDeviceDescriptorArray

harmony 鸿蒙OH_AudioRenderer_Callbacks_Struct

harmony 鸿蒙OH_AudioSession_DeactivatedEvent

harmony 鸿蒙OH_AudioSession_Strategy

harmony 鸿蒙_o_h_audio

harmony 鸿蒙Audio Error Codes

harmony 鸿蒙Ringtone Error Codes

harmony 鸿蒙js-apis-audio-sys

0  赞