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

The systemSoundManager module provides basic capabilities for managing system sounds, including setting and obtaining system ringtones and obtaining a player to play the system 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 alert tone.
TONE_CATEGORY_NOTIFICATION12+ 4 Notification alert tone.
TONE_CATEGORY_ALARM12+ 8 Alarm alert 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 alert 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 alert tone of SIM card 1.
SYSTEM_TONE_TYPE_SIM_CARD_1 1 SMS alert tone of SIM card 2.
SYSTEM_TONE_TYPE_NOTIFICATION 32 Notification alert 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 Customized 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

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

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

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

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

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

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

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 Media 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 system ringtones.

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 system ringtones.

System API: This is a system API.

System capability: SystemCapability.Multimedia.SystemSound.Core

Name Value Description
CALL_SIM_CARD_0 0 Haptic feedback with the ringtone for an incoming call on SIM card 1.
CALL_SIM_CARD_1 1 Haptic feedback with the ringtone for an incoming call on SIM card 2.
TEXT_MESSAGE_SIM_CARD_0 20 Haptic feedback with the ringtone for an incoming message on SIM card 1.
TEXT_MESSAGE_SIM_CARD_1 21 Haptic feedback with the ringtone for an incoming message on SIM card 2.
NOTIFICATION 40 Haptic feedback with the notification tone.

ToneHapticsMode14+

Enumerates the haptics modes in system ringtone 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 the haptic feedback is aligned with the system ringtone.
NON_SYNC 2 Non-sync mode, where the haptic feedback is not aligned with the system ringtone.

ToneHapticsSettings14+

Describes the haptics settings of a system ringtone.

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 system ringtones. 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

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

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

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 system ringtone.

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 system 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 system ringtone. For details about supported resources, see media.AVPlayer.
type RingtoneType Yes Type of the system ringtone.
callback AsyncCallback<void> Yes Callback used to return the result.

Example

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

let context: Context = getContext(this);
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 system 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 system ringtone. For details about supported resources, see media.AVPlayer.
type RingtoneType Yes Type of the system ringtone.

Return value

Type Description
Promise<void> Promise used to return the result.

Example

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

let context: Context = getContext(this);
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 system 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 system ringtone.
callback AsyncCallback<string> Yes Callback used to return the URI obtained.

Example

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

let context: Context = getContext(this);
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 system 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 system 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';

let context: Context = getContext(this);
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 system 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 system ringtone.
callback AsyncCallback<RingtonePlayer> Yes Callback used to return the player obtained.

Example

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

let context: Context = getContext(this);
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 system 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 system 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';

let context: Context = getContext(this);
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 system 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 system ringtone. For details about supported resources, see media.AVPlayer.
type RingtoneType Yes Type of the system ringtone.

Return value

Type Description
Promise<void> Promise used to return the result.

Error codes

For details about the error codes, see 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';

let context: common.BaseContext = getContext(this);
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 system 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 system ringtone.

Return value

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

Error codes

For details about the error codes, see 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';

let context: common.BaseContext = getContext(this);
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 system 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 system ringtone.

Return value

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

Error codes

For details about the error codes, see 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.

Example

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

let context: common.BaseContext = getContext(this);
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 alert 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 alert tone. For details about supported resources, see media.AVPlayer.
type SystemToneType Yes Type of the system alert tone.

Return value

Type Description
Promise<void> Promise used to return the result.

Error codes

For details about the error codes, see 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';

let context: common.BaseContext = getContext(this);
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 alert 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 alert tone.

Return value

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

Error codes

For details about the error codes, see 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';

let context: common.BaseContext = getContext(this);
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 alert 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 alert tone.

Return value

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

Error codes

For details about the error codes, see 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.

Example

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

let context: common.BaseContext = getContext(this);
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 system 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 system ringtone.

Return value

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

Error codes

For details about the error codes, see 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';

let context: common.BaseContext = getContext(this);
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 the list of attributes of the default system 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 system ringtone.

Return value

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

Error codes

For details about the error codes, see 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';

let context: common.BaseContext = getContext(this);
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 alert 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 alert tone.

Return value

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

Error codes

For details about the error codes, see 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';

let context: common.BaseContext = getContext(this);
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 the list of attributes of the default system alert 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 alert tone.

Return value

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

Error codes

For details about the error codes, see 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';

let context: common.BaseContext = getContext(this);
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 alert 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 alert tone.

Error codes

For details about the error codes, see 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';

let context: common.BaseContext = getContext(this);

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 alert 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 alert tone. For details about supported resources, see media.AVPlayer.

Return value

Type Description
Promise<void> Promise used to return the result.

Example

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

let context: Context = getContext(this);
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 an alarm alert 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 alarm alert tone.

Example

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

let context: Context = getContext(this);

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 the list of attributes of alarm alert 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 the alarm alert tones.

Error codes

For details about the error codes, see 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';

let context: common.BaseContext = getContext(this);

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 alert 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 alert 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 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';

let context: Context = getContext(this);
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 alert 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 used to return the result.

Error codes

For details about the error codes, see 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';

let context: Context = getContext(this);
let fd = 50; // Use the FD of the target alarm alert 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 customized 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 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';

let context: Context = getContext(this);
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 customized 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 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';

let context: Context = getContext(this);
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 one 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 used to return the result.

Error codes

For details about the error codes, see 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';

let context: Context = getContext(this);
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 system 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 Context Yes Application context.
type ToneHapticsType Yes Haptics type of the system ringtone.

Return value

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

Error codes

For details about the error codes, see 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';

let context: common.BaseContext = getContext(this);
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 system 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 Context Yes Application context.
type ToneHapticsType Yes Haptics type of the system ringtone.
settings ToneHapticsSettings Yes Haptics settings of the system ringtone.

Return value

Type Description
Promise<void> Promise used to return the result.

Error codes

For details about the error codes, see 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';

let context: common.BaseContext = getContext(this);
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 system ringtone 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 ringtone.

Return value

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

Error codes

For details about the error codes, see 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';

let context: common.BaseContext = getContext(this);

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 system 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 Context Yes Application context.
toneUri string Yes URI of the system ringtone. 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 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';

let context: common.BaseContext = getContext(this);
let toneUri: string = '/data/storage/el2/base/RingTone/alarms/test.ogg'; // Use the actual URI of the system 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 system 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 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 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';

let context: Context = getContext(this);
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 system ringtone player.

System capability: SystemCapability.Multimedia.SystemSound.Core

Type Description
_RingtonePlayer System ringtone player.

SystemTonePlayer11+

type SystemTonePlayer = _SystemTonePlayer;

Defines a system alert tone player.

System capability: SystemCapability.Multimedia.SystemSound.Core

Type Description
_SystemTonePlayer System alert tone player.

RingtoneOptions10+

type RingtoneOptions = _RingtoneOptions;

Defines the configuration of a system ringtone player.

System capability: SystemCapability.Multimedia.SystemSound.Core

Type Description
_RingtoneOptions Configuration of a system ringtone player.

SystemToneOptions11+

type SystemToneOptions = _SystemToneOptions;

Defines the configuration of a system alert tone player.

System capability: SystemCapability.Multimedia.SystemSound.Core

Type Description
_SystemToneOptions Configuration of a system alert tone player.