1# @ohos.multimedia.systemSoundManager (系统声音管理)(系统接口)
2
3系统声音管理提供管理系统声音的一些基础能力,包括对系统铃声的资源设置与读取、获取系统铃声播放器等。
4
5> **说明:**
6>
7> - 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8> - 本模块接口为系统接口。
9
10## 导入模块
11
12```ts
13import { systemSoundManager } from '@kit.AudioKit';
14```
15
16## 常量
17
18**系统接口:** 该接口为系统接口。
19
20**系统能力:** SystemCapability.Multimedia.SystemSound.Core
21
22| 名称                                      | 值   | 说明      |
23|------------------------------------------|-----|---------|
24| TONE_CATEGORY_RINGTONE<sup>12+</sup>     | 1   | 铃声类别。   |
25| TONE_CATEGORY_TEXT_MESSAGE<sup>12+</sup> | 2   | 短信铃声类别。 |
26| TONE_CATEGORY_NOTIFICATION<sup>12+</sup> | 4   | 通知铃声类别。 |
27| TONE_CATEGORY_ALARM<sup>12+</sup>        | 8   | 闹钟铃声类别。 |
28
29## RingtoneType
30
31枚举,铃声类型。
32
33**系统接口:** 该接口为系统接口。
34
35**系统能力:** SystemCapability.Multimedia.SystemSound.Core
36
37| 名称                            | 值  | 说明                                                                     |
38| ------------------------------- |----|------------------------------------------------------------------------|
39| RINGTONE_TYPE_DEFAULT<sup>(deprecated)</sup>           | 0  | 默认铃声类型。<br/> 从 API version 11 开始废弃。建议使用该枚举中的RINGTONE_TYPE_SIM_CARD_0替代。 |
40| RINGTONE_TYPE_SIM_CARD_0<sup>11+</sup> | 0  | sim卡1的铃声。                                                              |
41| RINGTONE_TYPE_MULTISIM<sup>(deprecated)</sup>          | 1  | 多SIM卡铃声类型。<br/> 从 API version 11 开始废弃。建议使用该枚举中的RINGTONE_TYPE_SIM_CARD_1替代。 |
42| RINGTONE_TYPE_SIM_CARD_1<sup>11+</sup> | 1  | sim卡2的铃声。                                                              |
43
44## SystemToneType<sup>11+</sup>
45
46枚举,系统铃声类型。
47
48**系统接口:** 该接口为系统接口。
49
50**系统能力:** SystemCapability.Multimedia.SystemSound.Core
51
52| 名称                            | 值   | 说明         |
53| ------------------------------- |-----|------------|
54| SYSTEM_TONE_TYPE_SIM_CARD_0     | 0   | sim卡1的短信提示音。 |
55| SYSTEM_TONE_TYPE_SIM_CARD_1     | 1   | sim卡2的短信提示音。 |
56| SYSTEM_TONE_TYPE_NOTIFICATION   | 32  | 通知提示音。     |
57
58
59## ToneCustomizedType<sup>12+</sup>
60
61枚举,铃声自定义类型。
62
63**系统接口:** 该接口为系统接口。
64
65**系统能力:** SystemCapability.Multimedia.SystemSound.Core
66
67| 名称                         | 值   | 说明         |
68| ----------------------------|-----|------------|
69| PRE_INSTALLED<sup>12+</sup> | 0   | 预安装铃声类型。 |
70| CUSTOMIZED<sup>12+</sup>    | 1   | 自定义铃声类型。 |
71
72## ToneAttrs<sup>12+</sup>
73
74管理铃声属性。在调用ToneAttrs<sup>12+</sup>的接口前,需要先通过[createCustomizedToneAttrs](#systemsoundmanagercreatecustomizedtoneattrs12)或[getDefaultRingtoneAttrs](#getdefaultringtoneattrs12)、[getRingtoneAttrList](#getringtoneattrlist12)等方法获取实例。
75
76### getTitle<sup>12+</sup>
77
78getTitle(): string
79
80获取铃声标题。
81
82**系统接口:** 该接口为系统接口。
83
84**系统能力:** SystemCapability.Multimedia.SystemSound.Core
85
86**返回值:**
87
88| 类型    | 说明  |
89|--------|-----|
90| string | 标题。 |
91
92**错误码:**
93
94| 错误码ID   | 错误信息              |
95|---------| -------------------- |
96| 202     | Caller is not a system application. |
97
98**示例:**
99
100```ts
101toneAttrs.getTitle();
102```
103
104### setTitle<sup>12+</sup>
105
106setTitle(title: string): void
107
108设置铃声标题。
109
110**系统接口:** 该接口为系统接口。
111
112**系统能力:** SystemCapability.Multimedia.SystemSound.Core
113
114**参数:**
115
116| 参数名  | 类型    | 必填 | 说明          |
117| -------| -------| ---- | ------------|
118| title  | string | 是   | 铃声的标题。   |
119
120**错误码:**
121
122| 错误码ID | 错误信息              |
123|-------| -------------------- |
124| 202   | Caller is not a system application. |
125| 401   | The parameters check failed. |
126
127**示例:**
128
129```ts
130let toneAttrs = systemSoundManager.createCustomizedToneAttrs();
131let title = 'text';
132toneAttrs.setTitle(title);
133```
134
135### getFileName<sup>12+</sup>
136
137getFileName(): string
138
139获取铃声文件名。
140
141**系统接口:** 该接口为系统接口。
142
143**系统能力:** SystemCapability.Multimedia.SystemSound.Core
144
145**返回值:**
146
147| 类型    | 说明   |
148|--------|------|
149| string | 文件名。 |
150
151**错误码:**
152
153| 错误码ID | 错误信息              |
154|---------| -------------------- |
155| 202     | Caller is not a system application. |
156
157
158**示例:**
159
160```ts
161toneAttrs.getFileName();
162```
163
164### setFileName<sup>12+</sup>
165
166setFileName(name: string): void
167
168设置铃声文件名。
169
170**系统接口:** 该接口为系统接口。
171
172**系统能力:** SystemCapability.Multimedia.SystemSound.Core
173
174**参数:**
175
176| 参数名 | 类型    | 必填 | 说明         |
177| ------| -------|-----| ------------|
178| name  | string | 是   | 铃声的文件名。 |
179
180**错误码:**
181
182| 错误码ID | 错误信息              |
183|-------| -------------------- |
184| 202   | Caller is not a system application. |
185| 401   | The parameters check failed. |
186
187**示例:**
188
189```ts
190let toneAttrs = systemSoundManager.createCustomizedToneAttrs();
191let fileName = 'textFileName';
192toneAttrs.setFileName(fileName);
193```
194
195### getUri<sup>12+</sup>
196
197getUri(): string
198
199获取铃声资源路径。
200
201**系统接口:** 该接口为系统接口。
202
203**系统能力:** SystemCapability.Multimedia.SystemSound.Core
204
205**返回值:**
206
207| 类型    | 说明                                                      |
208|--------|---------------------------------------------------------|
209| string | uri(如:'/data/storage/el2/base/RingTone/alarms/test.ogg')。 |
210
211**错误码:**
212
213| 错误码ID | 错误信息              |
214|---------| -------------------- |
215| 202     | Caller is not a system application. |
216
217**示例:**
218
219```ts
220toneAttrs.getUri();
221```
222
223### getCustomizedType<sup>12+</sup>
224
225getCustomizedType(): string
226
227获取铃声自定义类型。
228
229**系统接口:** 该接口为系统接口。
230
231**系统能力:** SystemCapability.Multimedia.SystemSound.Core
232
233**返回值:**
234
235| 类型                                         | 说明      |
236|--------------------------------------------|---------|
237| [ToneCustomizedType](#tonecustomizedtype12) | 定制铃音类型。 |
238
239**错误码:**
240
241| 错误码ID   | 错误信息              |
242|---------| -------------------- |
243| 202     | Caller is not a system application. |
244
245**示例:**
246
247```ts
248toneAttrs.getCustomizedType();
249```
250
251### setCategory<sup>12+</sup>
252
253setCategory(category: number): void
254
255设置铃声类别。
256
257**系统接口:** 该接口为系统接口。
258
259**系统能力:** SystemCapability.Multimedia.SystemSound.Core
260
261**参数:**
262
263| 参数名      | 类型      | 必填 | 说明       |
264|----------| ---------| ---- |----------|
265| category | number   | 是   | 铃声类别,取值参考[铃声类别的常量](#常量)。  |
266
267**错误码:**
268
269| 错误码ID | 错误信息              |
270|-------| -------------------- |
271| 202   | Caller is not a system application. |
272| 401   | The parameters check failed. |
273
274**示例:**
275
276```ts
277let toneAttrs = systemSoundManager.createCustomizedToneAttrs();
278let categoryValue = systemSoundManager.TONE_CATEGORY_ALARM; // 需更改为实际所需类型常量
279toneAttrs.setCategory(categoryValue);
280```
281
282### getCategory<sup>12+</sup>
283
284getCategory(): string
285
286获取铃声类别。
287
288**系统接口:** 该接口为系统接口。
289
290**系统能力:** SystemCapability.Multimedia.SystemSound.Core
291
292**返回值:**
293
294| 类型    | 说明     |
295|--------|--------|
296| number | 铃声类别,取值参考[铃声类别的常量](#常量)。 |
297
298**错误码:**
299
300| 错误码ID   | 错误信息              |
301|---------| -------------------- |
302| 202     | Caller is not a system application. |
303
304
305**示例:**
306
307```ts
308toneAttrs.getCategory();
309```
310
311## ToneAttrsArray<sup>12+</sup>
312
313type ToneAttrsArray = Array&lt;[ToneAttrs](#toneattrs12)&gt;
314
315铃音属性数组。
316
317**系统能力:** SystemCapability.Multimedia.SystemSound.Core
318
319| 类型                                     | 说明      |
320|----------------------------------------|---------|
321| Array&lt;[ToneAttrs](#toneattrs12)&gt; | 铃音属性数组。 |
322
323## systemSoundManager.createCustomizedToneAttrs<sup>12+</sup>
324
325createCustomizedToneAttrs(): ToneAttrs
326
327创建自定义铃声属性。
328
329**系统接口:** 该接口为系统接口。
330
331**系统能力:** SystemCapability.Multimedia.SystemSound.Core
332
333**返回值:**
334
335| 类型                        | 说明         |
336|---------------------------| ------------ |
337| [ToneAttrs](#toneattrs12) | 铃声属性类。 |
338
339**错误码:**
340
341以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
342
343| 错误码ID   | 错误信息              |
344|---------| -------------------- |
345| 202     | Caller is not a system application. |
346
347**示例:**
348```ts
349let toneAttrs: systemSoundManager.ToneAttrs = systemSoundManager.createCustomizedToneAttrs();
350```
351## ToneHapticsFeature<sup>13+</sup>
352
353枚举,系统振动风格定义。
354
355**系统接口:** 该接口为系统接口。
356
357**系统能力:** SystemCapability.Multimedia.SystemSound.Core
358
359| 名称                          | 值 | 说明                 |
360| ----------------------------- | -- | -------------------- |
361| STANDARD| 0  | 标准振动风格。 |
362| GENTLE   | 1  | 轻柔振动风格。 |
363
364## ToneHapticsType<sup>13+</sup>
365
366type ToneHapticsType = RingtoneType | SystemToneType
367
368联合枚举,系统铃音的振动类型。
369
370**系统接口:** 该接口为系统接口。
371
372**系统能力:** SystemCapability.Multimedia.SystemSound.Core
373
374| 名称                                 | 说明         |
375| ------------------------------------|------------|
376| [RingtoneType](#ringtonetype)       | 通话铃音类型。 |
377| [SystemToneType](#systemtonetype11) | 系统短音类型。 |
378
379## ToneHapticsMode<sup>13+</sup>
380
381枚举,系统铃音场景的振动模式。
382
383**系统接口:** 该接口为系统接口。
384
385**系统能力:** SystemCapability.Multimedia.SystemSound.Core
386
387| 名称                          | 值 | 说明                 |
388| ----------------------------- | -- | -------------------- |
389| NONE        | 0  | 无振动模式。 |
390| SYNC        | 1  | 与铃音同步模式。 |
391| NON_SYNC    | 2  | 非同步模式。 |
392
393## ToneHapticsSettings<sup>13+</sup>
394
395系统铃音的振动设置。
396
397**系统接口:** 该接口为系统接口。
398
399**系统能力:** SystemCapability.Multimedia.SystemSound.Core
400
401| 名称          | 类型 | 只读 | 可选 | 说明                 |
402| ------------ | -- | -- | -- | -------------------- |
403| mode | [ToneHapticsMode](#tonehapticsmode13) | 否 | 否 | 系统铃音的振动模式。 |
404| hapticsUri | string                          | 否 | 是 | 系统铃音的振动路径,当振动模式不是非同步振动应该被忽略,振动的路径可通过[getToneHapticsList](#gettonehapticslist13)获取。 |
405
406## ToneHapticsAttrs<sup>13+</sup>
407
408系统铃音的振动属性。在调用ToneHapticsAttrs<sup>13+</sup>的接口前,需要先通过[getToneHapticsList](#gettonehapticslist13)或[getHapticsAttrsSyncedWithTone](#gethapticsattrssyncedwithtone13)方法获取实例。
409
410### getUri<sup>13+</sup>
411
412getUri(): string
413
414获取振动资源路径。
415
416**系统接口:** 该接口为系统接口。
417
418**系统能力:** SystemCapability.Multimedia.SystemSound.Core
419
420**返回值:**
421
422| 类型    | 说明  |
423|--------|-----|
424| string | uri(如:'/data/storage/el2/base/haptics/synchronized/alarms/test.json')。 |
425
426**错误码:**
427
428| 错误码ID   | 错误信息              |
429|---------| -------------------- |
430| 202     | Caller is not a system application. |
431
432**示例:**
433
434```ts
435toneHapticsAttrs.getUri();
436```
437
438### getTitle<sup>13+</sup>
439
440getTitle(): string
441
442获取振动标题。
443
444**系统接口:** 该接口为系统接口。
445
446**系统能力:** SystemCapability.Multimedia.SystemSound.Core
447
448**返回值:**
449
450| 类型    | 说明  |
451|--------|-----|
452| string | 标题。 |
453
454**错误码:**
455
456| 错误码ID   | 错误信息              |
457|---------| -------------------- |
458| 202     | Caller is not a system application. |
459
460**示例:**
461
462```ts
463toneHapticsAttrs.getTitle();
464```
465
466### getFileName<sup>13+</sup>
467
468getFileName(): string
469
470获取振动文件名。
471
472**系统接口:** 该接口为系统接口。
473
474**系统能力:** SystemCapability.Multimedia.SystemSound.Core
475
476**返回值:**
477
478| 类型    | 说明  |
479|--------|-----|
480| string | 文件名。 |
481
482**错误码:**
483
484| 错误码ID   | 错误信息              |
485|---------| -------------------- |
486| 202     | Caller is not a system application. |
487
488**示例:**
489
490```ts
491toneHapticsAttrs.getFileName();
492```
493
494## ToneHapticsAttrsArray<sup>13+</sup>
495
496type ToneHapticsAttrsArray = Array&lt;ToneHapticsAttrs&gt;
497
498系统铃音的振动属性数组。
499
500**系统能力:** SystemCapability.Multimedia.SystemSound.Core
501
502| 类型                                     | 说明      |
503|----------------------------------------|---------|
504| Array&lt;[ToneHapticsAttrs](#tonehapticsattrs13)&gt; | 系统铃音的振动属性数组。 |
505
506## systemSoundManager.getSystemSoundManager
507
508getSystemSoundManager(): SystemSoundManager
509
510获取系统声音管理器。
511
512**系统接口:** 该接口为系统接口。
513
514**系统能力:** SystemCapability.Multimedia.SystemSound.Core
515
516**返回值:**
517
518| 类型                          | 说明         |
519| ----------------------------- | ------------ |
520| [SystemSoundManager](#systemsoundmanager) | 系统声音管理类。 |
521
522**示例:**
523```ts
524let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
525```
526
527## SystemSoundManager
528
529管理系统声音。在调用SystemSoundManager的接口前,需要先通过[getSystemSoundManager](#systemsoundmanagergetsystemsoundmanager)创建实例。
530
531### setSystemRingtoneUri<sup>(deprecated)</sup>
532
533setSystemRingtoneUri(context: Context, uri: string, type: RingtoneType, callback: AsyncCallback&lt;void&gt;): void
534
535设置系统铃声uri,使用callback方式异步返回结果。
536
537> **说明:**
538> 从 API version 10 开始支持,从 API version 11 开始废弃,建议使用[setRingtoneUri](#setringtoneuri11)替代。
539
540**系统接口:** 该接口为系统接口。
541
542**系统能力:** SystemCapability.Multimedia.SystemSound.Core
543
544**参数:**
545
546| 参数名   | 类型                                      | 必填 | 说明                     |
547| -------- | ---------------------------------------- | ---- | ------------------------ |
548| context  | [Context](../apis-ability-kit/js-apis-inner-application-context.md)   | 是   | 当前应用的上下文。           |
549| uri      | string                                   | 是   | 被设置的系统铃声的uri,资源支持可参考[media.AVPlayer](../apis-media-kit/js-apis-media.md#avplayer9)。 |
550| type     | [RingtoneType](#ringtonetype)            | 是   | 被设置的系统铃声的类型。     |
551| callback | AsyncCallback&lt;void&gt;                | 是   | 回调返回设置成功或失败。     |
552
553**示例:**
554
555```ts
556import { BusinessError } from '@kit.BasicServicesKit';
557import { common } from '@kit.AbilityKit';
558
559let context: Context = getContext(this);
560let uri = 'file://data/test.wav'; // 需更改为目标铃声文件的uri
561let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_DEFAULT;
562
563let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
564systemSoundManagerInstance.setSystemRingtoneUri(context, uri, type, (err: BusinessError) => {
565  if (err) {
566    console.error(`Failed to set system ringtone uri. ${err}`);
567    return;
568  }
569  console.info(`Callback invoked to indicate a successful setting of the system ringtone uri.`);
570});
571```
572
573### setSystemRingtoneUri<sup>(deprecated)</sup>
574
575setSystemRingtoneUri(context: Context, uri: string, type: RingtoneType): Promise&lt;void&gt;
576
577设置系统铃声uri,使用Promise方式异步返回结果。
578
579> **说明:**
580> 从 API version 10 开始支持,从 API version 11 开始废弃,建议使用[setRingtoneUri](#setringtoneuri11)替代。
581
582**系统接口:** 该接口为系统接口。
583
584**系统能力:** SystemCapability.Multimedia.SystemSound.Core
585
586**参数:**
587
588| 参数名   | 类型                                      | 必填 | 说明                     |
589| -------- | ---------------------------------------- | ---- | ------------------------ |
590| context  | [Context](../apis-ability-kit/js-apis-inner-application-context.md)  | 是   | 当前应用的上下文。         |
591| uri      | string                                   | 是   | 被设置的系统铃声的uri,资源支持可参考[media.AVPlayer](../apis-media-kit/js-apis-media.md#avplayer9)。 |
592| type     | [RingtoneType](#ringtonetype)            | 是   | 被设置的系统铃声的类型。   |
593
594**返回值:**
595
596| 类型                | 说明                            |
597| ------------------- | ------------------------------- |
598| Promise&lt;void&gt; | Promise回调返回设置成功或失败。   |
599
600**示例:**
601
602```ts
603import { BusinessError } from '@kit.BasicServicesKit';
604import { common } from '@kit.AbilityKit';
605
606let context: Context = getContext(this);
607let uri = 'file://data/test.wav'; // 需更改为目标铃声文件的uri
608let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_DEFAULT;
609
610let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
611systemSoundManagerInstance.setSystemRingtoneUri(context, uri, type).then(() => {
612  console.info(`Promise returned to indicate a successful setting of the system ringtone uri.`);
613}).catch ((err: BusinessError) => {
614  console.error(`Failed to set the system ringtone uri ${err}`);
615});
616```
617
618### getSystemRingtoneUri<sup>(deprecated)</sup>
619
620getSystemRingtoneUri(context: Context, type: RingtoneType, callback: AsyncCallback&lt;string&gt;): void
621
622获取系统铃声uri,使用callback方式异步返回结果。
623
624> **说明:**
625> 从 API version 10 开始支持,从 API version 11 开始废弃,建议使用[getRingtoneUri](#getringtoneuri11)替代。
626
627**系统接口:** 该接口为系统接口。
628
629**系统能力:** SystemCapability.Multimedia.SystemSound.Core
630
631**参数:**
632
633| 参数名   | 类型                                                                    | 必填 | 说明                     |
634| -------- |-----------------------------------------------------------------------| ---- | ------------------------ |
635| context  | [Context](../apis-ability-kit/js-apis-inner-application-context.md)   | 是   | 当前应用的上下文。         |
636| type     | [RingtoneType](#ringtonetype)                                         | 是   | 待获取的系统铃声的类型。    |
637| callback | AsyncCallback&lt;string&gt;                                           | 是   | 回调返回获取的系统铃声uri。 |
638
639**示例:**
640
641```ts
642import { BusinessError } from '@kit.BasicServicesKit';
643import { common } from '@kit.AbilityKit';
644
645let context: Context = getContext(this);
646let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_DEFAULT;
647
648let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
649systemSoundManagerInstance.getSystemRingtoneUri(context, type, (err: BusinessError, value: string) => {
650  if (err) {
651    console.error(`Failed to get system ringtone uri. ${err}`);
652    return;
653  }
654  console.info(`Callback invoked to indicate the value of the system ringtone uri is obtained ${value}.`);
655});
656```
657
658### getSystemRingtoneUri<sup>(deprecated)</sup>
659
660getSystemRingtoneUri(context: Context, type: RingtoneType): Promise&lt;string&gt;
661
662获取系统铃声uri,使用Promise方式异步返回结果。
663
664> **说明:**
665> 从 API version 10 开始支持,从 API version 11 开始废弃,建议使用[getRingtoneUri](#getringtoneuri11)替代。
666
667**系统接口:** 该接口为系统接口。
668
669**系统能力:** SystemCapability.Multimedia.SystemSound.Core
670
671**参数:**
672
673| 参数名   | 类型                                                                   | 必填 | 说明                     |
674| -------- |----------------------------------------------------------------------| ---- | ------------------------ |
675| context  | [Context](../apis-ability-kit/js-apis-inner-application-context.md)  | 是   | 当前应用的上下文。         |
676| type     | [RingtoneType](#ringtonetype)                                        | 是   | 被设置的系统铃声的类型。   |
677
678**返回值:**
679
680| 类型                | 说明                                |
681| ------------------- | ---------------------------------- |
682| Promise&lt;string&gt; | Promise回调返回获取的系统铃声uri。 |
683
684**示例:**
685
686```ts
687import { BusinessError } from '@kit.BasicServicesKit';
688import { common } from '@kit.AbilityKit';
689
690let context: Context = getContext(this);
691let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_DEFAULT;
692
693let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
694systemSoundManagerInstance.getSystemRingtoneUri(context, type).then((value: string) => {
695  console.info(`Promise returned to indicate that the value of the system ringtone uri is obtained ${value}.`);
696}).catch ((err: BusinessError) => {
697  console.error(`Failed to get the system ringtone uri ${err}`);
698});
699```
700
701### getSystemRingtonePlayer<sup>(deprecated)</sup>
702
703getSystemRingtonePlayer(context: Context, type: RingtoneType, callback: AsyncCallback&lt;RingtonePlayer&gt;): void
704
705获取系统铃声播放器,使用callback方式异步返回结果。
706
707> **说明:**
708> 从 API version 10 开始支持,从 API version 11 开始废弃,建议使用[getRingtonePlayer](#getringtoneplayer11)替代。
709
710**系统接口:** 该接口为系统接口。
711
712**系统能力:** SystemCapability.Multimedia.SystemSound.Core
713
714**参数:**
715
716| 参数名   | 类型                                      | 必填 | 说明                         |
717| -------- | -----------------------------------------| ---- | --------------------------- |
718| context  | [Context](../apis-ability-kit/js-apis-inner-application-context.md)  | 是   | 当前应用的上下文。            |
719| type     | [RingtoneType](#ringtonetype)            | 是   | 待获取播放器的系统铃声的类型。 |
720| callback | AsyncCallback&lt;[RingtonePlayer](js-apis-inner-multimedia-ringtonePlayer-sys.md#ringtoneplayer)&gt; | 是 | 回调返回获取的系统铃声播放器。 |
721
722**示例:**
723
724```ts
725import { BusinessError } from '@kit.BasicServicesKit';
726import { common } from '@kit.AbilityKit';
727
728let context: Context = getContext(this);
729let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_DEFAULT;
730let systemRingtonePlayer: systemSoundManager.RingtonePlayer | undefined = undefined;
731
732let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
733systemSoundManagerInstance.getSystemRingtonePlayer(context, type, (err: BusinessError, value: systemSoundManager.RingtonePlayer) => {
734  if (err) {
735    console.error(`Failed to get system ringtone player. ${err}`);
736    return;
737  }
738  console.info(`Callback invoked to indicate the value of the system ringtone player is obtained.`);
739  systemRingtonePlayer = value;
740});
741```
742
743### getSystemRingtonePlayer<sup>(deprecated)</sup>
744
745getSystemRingtonePlayer(context: Context, type: RingtoneType): Promise&lt;RingtonePlayer&gt;
746
747获取系统铃声播放器,使用Promise方式异步返回结果。
748
749> **说明:**
750> 从 API version 10 开始支持,从 API version 11 开始废弃,建议使用[getRingtonePlayer](#getringtoneplayer11)替代。
751
752**系统接口:** 该接口为系统接口。
753
754**系统能力:** SystemCapability.Multimedia.SystemSound.Core
755
756**参数:**
757
758| 参数名   | 类型                                                                  | 必填 | 说明                         |
759| -------- |---------------------------------------------------------------------| ---- | --------------------------- |
760| context  | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是   | 当前应用的上下文。            |
761| type     | [RingtoneType](#ringtonetype)                                       | 是   | 待获取播放器的系统铃声的类型。 |
762
763**返回值:**
764
765| 类型                | 说明                            |
766| ------------------- | ------------------------------- |
767| Promise&lt;[RingtonePlayer](js-apis-inner-multimedia-ringtonePlayer-sys.md#ringtoneplayer)&gt; | Promise回调返回获取的系统铃声播放器。 |
768
769**示例:**
770
771```ts
772import { BusinessError } from '@kit.BasicServicesKit';
773import { common } from '@kit.AbilityKit';
774
775let context: Context = getContext(this);
776let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_DEFAULT;
777let systemRingtonePlayer: systemSoundManager.RingtonePlayer | undefined = undefined;
778
779let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
780systemSoundManagerInstance.getSystemRingtonePlayer(context, type).then((value: systemSoundManager.RingtonePlayer) => {
781  console.info(`Promise returned to indicate that the value of the system ringtone player is obtained.`);
782  systemRingtonePlayer = value;
783}).catch ((err: BusinessError) => {
784  console.error(`Failed to get the system ringtone player ${err}`);
785});
786```
787
788### setRingtoneUri<sup>11+</sup>
789
790setRingtoneUri(context: BaseContext, uri: string, type: RingtoneType): Promise&lt;void&gt;
791
792设置系统铃声uri,使用Promise方式异步返回结果。
793
794**系统接口:** 该接口为系统接口。
795
796**系统能力:** SystemCapability.Multimedia.SystemSound.Core
797
798**参数:**
799
800| 参数名   | 类型                            | 必填 | 说明                     |
801| -------- |-------------------------------| ---- | ------------------------ |
802| context  | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md)            | 是   | 当前应用的上下文。         |
803| uri      | string                        | 是   | 被设置的系统铃声的uri,资源支持可参考[media.AVPlayer](../apis-media-kit/js-apis-media.md#avplayer9)。 |
804| type     | [RingtoneType](#ringtonetype) | 是   | 被设置的系统铃声的类型。   |
805
806**返回值:**
807
808| 类型                | 说明                            |
809| ------------------- | ------------------------------- |
810| Promise&lt;void&gt; | Promise回调返回设置成功或失败。   |
811
812**错误码:**
813
814以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
815
816| 错误码ID | 错误信息              |
817| ------- | --------------------- |
818| 202 | Caller is not a system application. |
819| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
820| 5400103 | I/O error. |
821
822**示例:**
823
824```ts
825import { BusinessError } from '@kit.BasicServicesKit';
826import { common } from '@kit.AbilityKit';
827
828let context: common.BaseContext = getContext(this);
829let uri = 'file://data/test.wav'; // 需更改为目标铃声文件的uri
830let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_SIM_CARD_0;
831
832let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
833systemSoundManagerInstance.setRingtoneUri(context, uri, type).then(() => {
834  console.info(`Promise returned to indicate a successful setting of the system ringtone uri.`);
835}).catch ((err: BusinessError) => {
836  console.error(`Failed to set the system ringtone uri ${err}`);
837});
838```
839
840### getRingtoneUri<sup>11+</sup>
841
842getRingtoneUri(context: BaseContext, type: RingtoneType): Promise&lt;string&gt;
843
844获取系统铃声uri,使用Promise方式异步返回结果。
845
846**系统接口:** 该接口为系统接口。
847
848**系统能力:** SystemCapability.Multimedia.SystemSound.Core
849
850**参数:**
851
852| 参数名   | 类型                             | 必填 | 说明                     |
853| -------- | -------------------------------| ---- | ------------------------ |
854| context  | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md)| 是   | 当前应用的上下文。         |
855| type     | [RingtoneType](#ringtonetype)  | 是   | 被设置的系统铃声的类型。   |
856
857**返回值:**
858
859| 类型                | 说明                                |
860| ------------------- | ---------------------------------- |
861| Promise&lt;string&gt; | Promise回调返回获取的系统铃声uri。 |
862
863**错误码:**
864
865以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
866
867| 错误码ID | 错误信息              |
868| -------- | --------------------- |
869| 202 | Caller is not a system application. |
870| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
871| 5400103  | I/O error. |
872
873**示例:**
874
875```ts
876import { BusinessError } from '@kit.BasicServicesKit';
877import { common } from '@kit.AbilityKit';
878
879let context: common.BaseContext = getContext(this);
880let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_SIM_CARD_0;
881
882let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
883systemSoundManagerInstance.getRingtoneUri(context, type).then((value: string) => {
884  console.info(`Promise returned to indicate that the value of the system ringtone uri is obtained ${value}.`);
885}).catch ((err: BusinessError) => {
886  console.error(`Failed to get the system ringtone uri ${err}`);
887});
888```
889
890### getRingtonePlayer<sup>11+</sup>
891
892getRingtonePlayer(context: BaseContext, type: RingtoneType): Promise&lt;RingtonePlayer&gt;
893
894获取系统铃声播放器,使用Promise方式异步返回结果。
895
896**系统接口:** 该接口为系统接口。
897
898**系统能力:** SystemCapability.Multimedia.SystemSound.Core
899
900**参数:**
901
902| 参数名   | 类型                              | 必填 | 说明                         |
903| -------- | --------------------------------| ---- | --------------------------- |
904| context  | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前应用的上下文。            |
905| type     | [RingtoneType](#ringtonetype)   | 是   | 待获取播放器的系统铃声的类型。 |
906
907**返回值:**
908
909| 类型                | 说明                            |
910| ------------------- | ------------------------------- |
911| Promise&lt;[RingtonePlayer](js-apis-inner-multimedia-ringtonePlayer-sys.md#ringtoneplayer)&gt; | Promise回调返回获取的系统铃声播放器。 |
912
913**错误码:**
914
915以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
916
917| 错误码ID | 错误信息              |
918| -------- | --------------------- |
919| 202 | Caller is not a system application. |
920| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
921
922**示例:**
923
924```ts
925import { BusinessError } from '@kit.BasicServicesKit';
926import { common } from '@kit.AbilityKit';
927
928let context: common.BaseContext = getContext(this);
929let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_SIM_CARD_0;
930let systemRingtonePlayer: systemSoundManager.RingtonePlayer | undefined = undefined;
931
932let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
933systemSoundManagerInstance.getRingtonePlayer(context, type).then((value: systemSoundManager.RingtonePlayer) => {
934  console.info(`Promise returned to indicate that the value of the system ringtone player is obtained.`);
935  systemRingtonePlayer = value;
936}).catch ((err: BusinessError) => {
937  console.error(`Failed to get the system ringtone player ${err}`);
938});
939```
940
941### setSystemToneUri<sup>11+</sup>
942
943setSystemToneUri(context: BaseContext, uri: string, type: SystemToneType): Promise&lt;void&gt;
944
945设置系统提示音uri,使用Promise方式异步返回结果。
946
947**系统接口:** 该接口为系统接口。
948
949**系统能力:** SystemCapability.Multimedia.SystemSound.Core
950
951**参数:**
952
953| 参数名   | 类型                                  | 必填 | 说明                     |
954| -------- |-------------------------------------| ---- | ------------------------ |
955| context  | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前应用的上下文。         |
956| uri      | string                              | 是   | 被设置的系统提示音的uri,资源支持可参考[media.AVPlayer](../apis-media-kit/js-apis-media.md#avplayer9)。 |
957| type     | [SystemToneType](#systemtonetype11) | 是   | 被设置的系统提示音的类型。   |
958
959**返回值:**
960
961| 类型                | 说明                            |
962| ------------------- | ------------------------------- |
963| Promise&lt;void&gt; | Promise回调返回设置成功或失败。   |
964
965**错误码:**
966
967以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
968
969| 错误码ID | 错误信息              |
970| ------- | --------------------- |
971| 202 | Caller is not a system application. |
972| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
973| 5400103 | I/O error. |
974
975**示例:**
976
977```ts
978import { BusinessError } from '@kit.BasicServicesKit';
979import { common } from '@kit.AbilityKit';
980
981let context: common.BaseContext = getContext(this);
982let uri = 'file://data/test.wav'; // 需更改为目标铃声文件的uri
983let type: systemSoundManager.SystemToneType = systemSoundManager.SystemToneType.SYSTEM_TONE_TYPE_SIM_CARD_0;
984
985let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
986systemSoundManagerInstance.setSystemToneUri(context, uri, type).then(() => {
987  console.info(`Promise returned to indicate a successful setting of the system tone uri.`);
988}).catch ((err: BusinessError) => {
989  console.error(`Failed to set the system tone uri ${err}`);
990});
991```
992
993### getSystemToneUri<sup>11+</sup>
994
995getSystemToneUri(context: BaseContext, type: SystemToneType): Promise&lt;string&gt;
996
997获取系统提示音uri,使用Promise方式异步返回结果。
998
999**系统接口:** 该接口为系统接口。
1000
1001**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1002
1003**参数:**
1004
1005| 参数名   | 类型                                  | 必填 | 说明                     |
1006| -------- |-------------------------------------| ---- | ------------------------ |
1007| context  | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前应用的上下文。         |
1008| type     | [SystemToneType](#systemtonetype11) | 是   | 被设置的系统提示音的类型。   |
1009
1010**返回值:**
1011
1012| 类型                | 说明                                |
1013| ------------------- | ---------------------------------- |
1014| Promise&lt;string&gt; | Promise回调返回获取的系统提示音uri。 |
1015
1016**错误码:**
1017
1018以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
1019
1020| 错误码ID | 错误信息              |
1021| ------- | --------------------- |
1022| 202 | Caller is not a system application. |
1023| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
1024| 5400103 | I/O error. |
1025
1026**示例:**
1027
1028```ts
1029import { BusinessError } from '@kit.BasicServicesKit';
1030import { common } from '@kit.AbilityKit';
1031
1032let context: common.BaseContext = getContext(this);
1033let type: systemSoundManager.SystemToneType = systemSoundManager.SystemToneType.SYSTEM_TONE_TYPE_SIM_CARD_0;
1034
1035let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1036systemSoundManagerInstance.getSystemToneUri(context, type).then((value: string) => {
1037  console.info(`Promise returned to indicate that the value of the system tone uri is obtained ${value}.`);
1038}).catch ((err: BusinessError) => {
1039  console.error(`Failed to get the system tone uri ${err}`);
1040});
1041```
1042
1043### getSystemTonePlayer<sup>11+</sup>
1044
1045getSystemTonePlayer(context: BaseContext, type: SystemToneType): Promise&lt;SystemTonePlayer&gt;
1046
1047获取系统提示音播放器,使用Promise方式异步返回结果。
1048
1049**系统接口:** 该接口为系统接口。
1050
1051**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1052
1053**参数:**
1054
1055| 参数名   | 类型                                  | 必填 | 说明                         |
1056| -------- |-------------------------------------| ---- | --------------------------- |
1057| context  | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前应用的上下文。            |
1058| type     | [SystemToneType](#systemtonetype11) | 是   | 待获取播放器的系统提示音的类型。 |
1059
1060**返回值:**
1061
1062| 类型                                                                                               | 说明                            |
1063|--------------------------------------------------------------------------------------------------| ------------------------------- |
1064| Promise&lt;[SystemTonePlayer](js-apis-inner-multimedia-systemTonePlayer-sys.md#systemtoneplayer)&gt; | Promise回调返回获取的系统提示音播放器。 |
1065
1066**错误码:**
1067
1068以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
1069
1070| 错误码ID | 错误信息              |
1071| ------- | --------------------- |
1072| 202 | Caller is not a system application. |
1073| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
1074
1075**示例:**
1076
1077```ts
1078import { BusinessError } from '@kit.BasicServicesKit';
1079import { common } from '@kit.AbilityKit';
1080
1081let context: common.BaseContext = getContext(this);
1082let type: systemSoundManager.SystemToneType = systemSoundManager.SystemToneType.SYSTEM_TONE_TYPE_SIM_CARD_0;
1083let systemTonePlayer: systemSoundManager.SystemTonePlayer | undefined = undefined;
1084
1085let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1086systemSoundManagerInstance.getSystemTonePlayer(context, type).then((value: systemSoundManager.SystemTonePlayer) => {
1087  console.info(`Promise returned to indicate that the value of the system tone player is obtained.`);
1088    systemTonePlayer = value;
1089}).catch ((err: BusinessError) => {
1090  console.error(`Failed to get the system tone player ${err}`);
1091});
1092```
1093
1094### getDefaultRingtoneAttrs<sup>12+</sup>
1095
1096getDefaultRingtoneAttrs(context: BaseContext, type: RingtoneType): Promise&lt;ToneAttrs&gt;
1097
1098获取系统铃声的属性,使用Promise方式异步返回结果。
1099
1100**系统接口:** 该接口为系统接口。
1101
1102**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1103
1104**参数:**
1105
1106| 参数名   | 类型                                  | 必填 | 说明                         |
1107| -------- |-------------------------------------| ---- | --------------------------- |
1108| context  |[BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前应用的上下文。            |
1109| type     |[RingtoneType](#ringtonetype)        | 是   | 被设置的系统铃声的类型。  |
1110
1111**返回值:**
1112
1113| 类型                                       | 说明                  |
1114|------------------------------------------|---------------------|
1115| Promise&lt;[ToneAttrs](#toneattrs12)&gt; | Promise回调返回系统铃声的属性。 |
1116
1117**错误码:**
1118
1119以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
1120
1121| 错误码ID | 错误信息              |
1122| ------- | --------------------- |
1123| 202 | Caller is not a system application. |
1124| 401 | The parameters check failed. |
1125| 5400103 | I/O error. |
1126
1127**示例:**
1128
1129```ts
1130import { BusinessError } from '@kit.BasicServicesKit';
1131import { common } from '@kit.AbilityKit';
1132
1133let context: common.BaseContext = getContext(this);
1134let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_SIM_CARD_0;
1135
1136let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1137systemSoundManagerInstance.getDefaultRingtoneAttrs(context, type).then((value: systemSoundManager.ToneAttrs) => {
1138  console.info(`Promise returned to indicate that the value of the attributes of the default ringtone is obtained.`);
1139}).catch ((err: BusinessError) => {
1140  console.error(`Failed to get the default ring tone attrs ${err}`);
1141});
1142```
1143
1144### getRingtoneAttrList<sup>12+</sup>
1145
1146getRingtoneAttrList(context: BaseContext, type: RingtoneType): Promise&lt;ToneAttrsArray&gt;
1147
1148获取系统铃声的属性列表,使用Promise方式异步返回结果。
1149
1150**系统接口:** 该接口为系统接口。
1151
1152**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1153
1154**参数:**
1155
1156| 参数名   | 类型                                  | 必填 | 说明                         |
1157| -------- |-------------------------------------| ---- | --------------------------- |
1158| context  |[BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前应用的上下文。            |
1159| type     |[RingtoneType](#ringtonetype)        | 是   | 被设置的系统铃声的类型。  |
1160
1161**返回值:**
1162
1163| 类型                                                 | 说明                    |
1164|----------------------------------------------------|-----------------------|
1165| Promise&lt;[ToneAttrsArray](#toneattrsarray12)&gt; | Promise回调返回系统铃声的属性列表。 |
1166
1167**错误码:**
1168
1169以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
1170
1171| 错误码ID | 错误信息              |
1172| ------- | --------------------- |
1173| 202 | Caller is not a system application. |
1174| 401 | The parameters check failed. |
1175| 5400103 | I/O error. |
1176
1177**示例:**
1178
1179```ts
1180import { BusinessError } from '@kit.BasicServicesKit';
1181import { common } from '@kit.AbilityKit';
1182
1183let context: common.BaseContext = getContext(this);
1184let type: systemSoundManager.RingtoneType = systemSoundManager.RingtoneType.RINGTONE_TYPE_SIM_CARD_0;
1185
1186let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1187systemSoundManagerInstance.getRingtoneAttrList(context, type).then((value: systemSoundManager.ToneAttrsArray) => {
1188  console.info(`Promise returned to indicate that the value of the attribute list of ringtone is obtained.`);
1189}).catch ((err: BusinessError) => {
1190  console.error(`Failed to get the attribute list of ringtone ${err}`);
1191});
1192```
1193
1194### getDefaultSystemToneAttrs<sup>12+</sup>
1195
1196getDefaultSystemToneAttrs(context: BaseContext, type: SystemToneType): Promise&lt;ToneAttrs&gt;
1197
1198获取系统提示音的属性,使用Promise方式异步返回结果。
1199
1200**系统接口:** 该接口为系统接口。
1201
1202**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1203
1204**参数:**
1205
1206| 参数名   | 类型                                                                          | 必填 | 说明                         |
1207| -------- |-----------------------------------------------------------------------------| ---- | --------------------------- |
1208| context  | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前应用的上下文。            |
1209| type     | [SystemToneType](#systemtonetype11)                                         | 是   | 待获取播放器的系统提示音的类型。 |
1210
1211**返回值:**
1212
1213| 类型                                      | 说明                   |
1214|-----------------------------------------|----------------------|
1215| Promise&lt;[ToneAttrs](#toneattrs12)&gt; | Promise回调返回系统提示音的属性。 |
1216
1217**错误码:**
1218
1219以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
1220
1221| 错误码ID | 错误信息              |
1222| ------- | --------------------- |
1223| 202 | Caller is not a system application. |
1224| 401 | The parameters check failed. |
1225| 5400103 | I/O error. |
1226
1227**示例:**
1228
1229```ts
1230import { BusinessError } from '@kit.BasicServicesKit';
1231import { common } from '@kit.AbilityKit';
1232
1233let context: common.BaseContext = getContext(this);
1234let type: systemSoundManager.SystemToneType = systemSoundManager.SystemToneType.SYSTEM_TONE_TYPE_SIM_CARD_0;
1235
1236let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1237systemSoundManagerInstance.getDefaultSystemToneAttrs(context, type).then((value: systemSoundManager.ToneAttrs) => {
1238  console.info(`Promise returned to indicate that the value of the attributes of the system ringtone is obtained.`);
1239}).catch ((err: BusinessError) => {
1240  console.error(`Failed to get the system tone attrs ${err}`);
1241});
1242```
1243
1244### getSystemToneAttrList<sup>12+</sup>
1245
1246getSystemToneAttrList(context: BaseContext, type: SystemToneType): Promise&lt;ToneAttrsArray&gt;
1247
1248获取系统提示音的属性列表,使用Promise方式异步返回结果。
1249
1250**系统接口:** 该接口为系统接口。
1251
1252**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1253
1254**参数:**
1255
1256| 参数名   | 类型                                                                          | 必填 | 说明                         |
1257| -------- |-----------------------------------------------------------------------------| ---- | --------------------------- |
1258| context  | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前应用的上下文。            |
1259| type     | [SystemToneType](#systemtonetype11)                                         | 是   | 待获取播放器的系统提示音的类型。  |
1260
1261**返回值:**
1262
1263| 类型                                                | 说明                     |
1264|---------------------------------------------------|------------------------|
1265| Promise&lt;[ToneAttrsArray](#toneattrsarray12)&gt; | Promise回调返回系统提示音的属性列表。 |
1266
1267**错误码:**
1268
1269以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
1270
1271| 错误码ID | 错误信息              |
1272| ------- | --------------------- |
1273| 202 | Caller is not a system application. |
1274| 401 | The parameters check failed. |
1275| 5400103 | I/O error. |
1276
1277**示例:**
1278
1279```ts
1280import { BusinessError } from '@kit.BasicServicesKit';
1281import { common } from '@kit.AbilityKit';
1282
1283let context: common.BaseContext = getContext(this);
1284let type: systemSoundManager.SystemToneType = systemSoundManager.SystemToneType.SYSTEM_TONE_TYPE_SIM_CARD_0;
1285
1286let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1287systemSoundManagerInstance.getSystemToneAttrList(context, type).then((value: systemSoundManager.ToneAttrsArray) => {
1288  console.info(`Promise returned to indicate that the value of the attribute list of system tone is obtained.`);
1289}).catch ((err: BusinessError) => {
1290  console.error(`Failed to get the attribute list of system tone ${err}`);
1291});
1292```
1293
1294### getDefaultAlarmToneAttrs<sup>12+</sup>
1295
1296getDefaultAlarmToneAttrs(context: BaseContext): Promise&lt;ToneAttrs&gt;
1297
1298获取系统闹铃的属性,使用Promise方式异步返回结果。
1299
1300**系统接口:** 该接口为系统接口。
1301
1302**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1303
1304**参数:**
1305
1306| 参数名   | 类型         | 必填 | 说明        |
1307| --------|------------| ---- |-----------|
1308| context | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md) | 是   | 当前应用的上下文。 |
1309
1310**返回值:**
1311
1312| 类型                                      | 说明                  |
1313|-----------------------------------------|---------------------|
1314| Promise&lt;[ToneAttrs](#toneattrs12)&gt; | Promise回调返回系统闹铃的属性。 |
1315
1316**错误码:**
1317
1318以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
1319
1320| 错误码ID | 错误信息              |
1321| ------- | --------------------- |
1322| 202 | Caller is not a system application. |
1323| 401 | The parameters check failed. |
1324| 5400103 | I/O error. |
1325
1326**示例:**
1327
1328```ts
1329import { BusinessError } from '@kit.BasicServicesKit';
1330import { common } from '@kit.AbilityKit';
1331
1332let context: common.BaseContext = getContext(this);
1333
1334let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1335systemSoundManagerInstance.getDefaultAlarmToneAttrs(context).then((value: systemSoundManager.ToneAttrs) => {
1336  console.info(`Promise returned to indicate that the value of the attributes of the default alarm tone is obtained.`);
1337}).catch ((err: BusinessError) => {
1338  console.error(`Failed to get the default alarm tone attrs ${err}`);
1339});
1340```
1341
1342### setAlarmToneUri<sup>12+</sup>
1343
1344setAlarmToneUri(context: Context, uri: string): Promise&lt;void&gt;
1345
1346设置系统闹铃uri,使用Promise方式异步返回结果。
1347
1348**系统接口:** 该接口为系统接口。
1349
1350**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1351
1352**参数:**
1353
1354| 参数名   | 类型        | 必填 | 说明   |
1355| -------- | --------- | ---- |--------------------------|
1356| context  | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是   | 当前应用的上下文。                                                                           |
1357| uri      | string    | 是   | 被设置的系统闹铃的uri,资源支持可参考[media.AVPlayer](../apis-media-kit/js-apis-media.md#avplayer9)。 |
1358
1359**返回值:**
1360
1361| 类型                | 说明                   |
1362| ------------------- |----------------------|
1363| Promise&lt;void&gt; | Promise回调返回设置成功或失败。  |
1364
1365**示例:**
1366
1367```ts
1368import { BusinessError } from '@kit.BasicServicesKit';
1369import { common } from '@kit.AbilityKit';
1370
1371let context: Context = getContext(this);
1372let uri = 'file://data/test.wav'; // 需更改为目标铃声文件的uri
1373
1374let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1375systemSoundManagerInstance.setAlarmToneUri(context, uri).then(() => {
1376  console.info(`Promise returned to indicate a successful setting of the alarm tone uri.`);
1377}).catch ((err: BusinessError) => {
1378  console.error(`Failed to set the alarm tone uri ${err}`);
1379});
1380```
1381
1382### getAlarmToneUri<sup>12+</sup>
1383
1384getAlarmToneUri(context: Context): Promise&lt;string&gt;
1385
1386获取系统当前闹铃uri,使用Promise方式异步返回结果。
1387
1388**系统接口:** 该接口为系统接口。
1389
1390**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1391
1392**参数:**
1393
1394| 参数名   | 类型      | 必填 | 说明              |
1395| -------- | --------| ---- |-----------------|
1396| context  | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是   | 当前应用的上下文。  |
1397
1398**返回值:**
1399
1400| 类型                    | 说明                    |
1401|-----------------------|-----------------------|
1402| Promise&lt;string&gt; | Promise回调返回系统当前闹铃uri。 |
1403
1404**示例:**
1405
1406```ts
1407import { BusinessError } from '@kit.BasicServicesKit';
1408import { common } from '@kit.AbilityKit';
1409
1410let context: Context = getContext(this);
1411
1412let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1413systemSoundManagerInstance.getAlarmToneUri(context).then((value: string) => {
1414  console.info(`Promise returned to indicate that the value of alarm tone uri.`);
1415}).catch ((err: BusinessError) => {
1416  console.error(`Failed to get the alarm tone uri ${err}`);
1417});
1418```
1419
1420### getAlarmToneAttrList<sup>12+</sup>
1421
1422getAlarmToneAttrList(context: BaseContext): Promise&lt;ToneAttrsArray&gt;
1423
1424获取全部闹铃属性列表,使用Promise方式异步返回结果。
1425
1426**系统接口:** 该接口为系统接口。
1427
1428**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1429
1430**参数:**
1431
1432| 参数名   | 类型            | 必填 | 说明                         |
1433| -------- |--------------| ---- | --------------------------- |
1434| context  | [BaseContext](../apis-ability-kit/js-apis-inner-application-baseContext.md)  | 是   | 当前应用的上下文。            |
1435
1436**返回值:**
1437
1438| 类型                                                 | 说明                   |
1439|----------------------------------------------------|----------------------|
1440| Promise&lt;[ToneAttrsArray](#toneattrsarray12)&gt; | Promise回调返回全部闹铃属性列表。 |
1441
1442**错误码:**
1443
1444以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
1445
1446| 错误码ID | 错误信息              |
1447| ------- | --------------------- |
1448| 202 | Caller is not a system application. |
1449| 401 | The parameters check failed. |
1450| 5400103 | I/O error. |
1451
1452**示例:**
1453
1454```ts
1455import { BusinessError } from '@kit.BasicServicesKit';
1456import { common } from '@kit.AbilityKit';
1457
1458let context: common.BaseContext = getContext(this);
1459
1460let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1461systemSoundManagerInstance.getAlarmToneAttrList(context).then((value: systemSoundManager.ToneAttrsArray) => {
1462  console.info(`Promise returned to indicate that the value of the attribute list of alarm tone is obtained.`);
1463}).catch ((err: BusinessError) => {
1464  console.error(`Failed to get the attribute list of alarm tone ${err}`);
1465});
1466```
1467
1468### openAlarmTone<sup>12+</sup>
1469
1470openAlarmTone(context: Context, uri: string): Promise&lt;number&gt;
1471
1472打开闹铃文件,使用Promise方式异步返回结果。
1473
1474**系统接口:** 该接口为系统接口。
1475
1476**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1477
1478**参数:**
1479
1480| 参数名   | 类型       | 必填 | 说明                                                                                  |
1481| -------- | ---------| ---- |-------------------------------------------------------------------------------------|
1482| context  | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是   | 当前应用的上下文。                                                                           |
1483| uri      | string   | 是   | 被设置的系统闹铃的uri,资源支持可参考[media.AVPlayer](../apis-media-kit/js-apis-media.md#avplayer9)。 |
1484
1485**返回值:**
1486
1487| 类型                    | 说明             |
1488|-----------------------|----------------|
1489| Promise&lt;number&gt; | Promise回调返回fd。 |
1490
1491**错误码:**
1492
1493以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
1494
1495| 错误码ID | 错误信息              |
1496| ------- | --------------------- |
1497| 202 | Caller is not a system application. |
1498| 401 | The parameters check failed. |
1499| 5400103 | I/O error. |
1500| 20700001 | Tone type mismatch, e.g. tone of uri is notification instead of alarm. |
1501
1502**示例:**
1503
1504```ts
1505import { BusinessError } from '@kit.BasicServicesKit';
1506import { common } from '@kit.AbilityKit';
1507
1508let context: Context = getContext(this);
1509let uri = 'file://data/test.wav'; // 需更改为目标铃声文件的uri
1510
1511let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1512systemSoundManagerInstance.openAlarmTone(context, uri).then((value: number) => {
1513  console.info(`Promise returned to indicate the value of fd.`);
1514}).catch ((err: BusinessError) => {
1515  console.error(`Failed to open alarm tone ${err}`);
1516});
1517```
1518
1519### close<sup>12+</sup>
1520
1521close(fd: number): Promise&lt;void&gt;
1522
1523关闭闹铃文件,使用Promise方式异步返回结果。
1524
1525**系统接口:** 该接口为系统接口
1526
1527**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1528
1529**参数:**
1530
1531| 参数名 | 类型   | 必填 | 说明                                           |
1532|-----| --------| ---- |----------------------------------------------|
1533| fd  | number  | 是   | 文件描述符,通过[openAlarmTone](#openalarmtone12)获取。 |
1534
1535**返回值:**
1536
1537| 类型                  | 说明             |
1538|---------------------|----------------|
1539| Promise&lt;void&gt; | Promise回调返回设置成功或失败。 |
1540
1541**错误码:**
1542
1543以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
1544
1545| 错误码ID | 错误信息              |
1546| ------- | --------------------- |
1547| 202 | Caller is not a system application. |
1548| 401 | The parameters check failed. |
1549| 5400103 | I/O error. |
1550
1551**示例:**
1552
1553```ts
1554import { BusinessError } from '@kit.BasicServicesKit';
1555import { common } from '@kit.AbilityKit';
1556
1557let context: Context = getContext(this);
1558let fd = 50; // 需更改为目标铃声的fd
1559
1560let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1561systemSoundManagerInstance.close(fd).then(() => {
1562  console.info(`Promise returned to indicate that the fd has been close.`);
1563}).catch ((err: BusinessError) => {
1564  console.error(`Failed to close fd ${err}`);
1565});
1566```
1567
1568### addCustomizedTone<sup>12+</sup>
1569
1570addCustomizedTone(context: BaseContext, toneAttr: ToneAttrs, externalUri: string): Promise&lt;string&gt;
1571
1572通过铃音uri将自定义铃音添加到铃音库,使用Promise方式异步返回结果。
1573
1574**系统接口:** 该接口为系统接口。
1575
1576**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1577
1578**参数:**
1579
1580| 参数名 | 类型        | 必填 | 说明            |
1581|-----|-----------| ---- |---------------|
1582| context  | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是   | 当前应用的上下文。     |
1583| toneAttr  | ToneAttrs | 是   | 铃音属性。         |
1584| externalUri  | string    | 是   | 外部存储器中的铃音uri。 |
1585
1586**返回值:**
1587
1588| 类型                    | 说明                      |
1589|-----------------------|-------------------------|
1590| Promise&lt;string&gt; | Promise回调返回铃音在铃音库中的uri。 |
1591
1592**错误码:**
1593
1594以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
1595
1596| 错误码ID   | 错误信息              |
1597|---------| -------------------- |
1598| 201     | Permission denied. |
1599| 202     | Caller is not a system application. |
1600| 401     | The parameters check failed. |
1601| 5400102     | Operation is not allowed, e.g. ringtone to add is not customized. |
1602| 5400103 | I/O error. |
1603
1604**示例:**
1605
1606```ts
1607import { BusinessError } from '@kit.BasicServicesKit';
1608import { common } from '@kit.AbilityKit';
1609
1610let context: Context = getContext(this);
1611let title = 'test'; // 需更改为实际名称
1612let fileName = 'displayName_test'; // 需更改为实际文件名
1613let categoryValue = systemSoundManager.TONE_CATEGORY_ALARM;
1614
1615let toneAttrs = systemSoundManager.createCustomizedToneAttrs();
1616toneAttrs.setTitle(title);
1617toneAttrs.setFileName(fileName);
1618toneAttrs.setCategory(categoryValue);
1619
1620let path = 'file://data/test.ogg'; // 需更改为实际铃音uri
1621
1622let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1623systemSoundManagerInstance.addCustomizedTone(context, toneAttrs, path).then((value: string) => {
1624  console.info(`Promise returned to indicate that the value of tone uri in ringtone library.`);
1625}).catch ((err: BusinessError) => {
1626  console.error(`Failed to add customized tone ${err}`);
1627});
1628```
1629
1630### addCustomizedTone<sup>12+</sup>
1631
1632addCustomizedTone(context: BaseContext, toneAttr: ToneAttrs, fd: number, offset?: number, length?: number): Promise&lt;string&gt;
1633
1634通过文件描述符fd将自定义铃音添加到铃音库,使用Promise方式异步返回结果。
1635
1636**系统接口:** 该接口为系统接口。
1637
1638**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1639
1640**参数:**
1641
1642| 参数名 | 类型        | 必填 | 说明                                                                     |
1643|-----|-----------|----|------------------------------------------------------------------------|
1644| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是  | 当前应用的上下文。                                                              |
1645| toneAttr | [ToneAttrs](#toneattrs12) | 是  | 铃音属性。                                                                  |
1646| fd  | number    | 是  | 文件描述符,可通过[fs.open](../apis-core-file-kit/js-apis-file-fs.md#fsopen)获取。 |
1647| offset | number    | 否  | 读取数据的偏移量(以字节为单位)。默认情况下为0。                                              |
1648| length | number    | 否  | 读取的数据的长度(以字节为单位)。默认情况下,长度为偏移后的剩余全部字节数。                                 |
1649
1650**返回值:**
1651
1652| 类型                    | 说明                      |
1653|-----------------------|-------------------------|
1654| Promise&lt;string&gt; | Promise回调返回铃音在铃音库中的uri。 |
1655
1656**错误码:**
1657
1658以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
1659
1660| 错误码ID   | 错误信息              |
1661|---------| -------------------- |
1662| 201     | Permission denied. |
1663| 202     | Caller is not a system application. |
1664| 401     | The parameters check failed. |
1665| 5400102     | Operation is not allowed, e.g. ringtone to add is not customized. |
1666| 5400103 | I/O error. |
1667
1668**示例:**
1669
1670```ts
1671import { BusinessError } from '@kit.BasicServicesKit';
1672import { common } from '@kit.AbilityKit';
1673
1674let context: Context = getContext(this);
1675let title = 'test'; // 需更改为实际名称
1676let fileName = 'displayName_test'; // 需更改为实际文件名
1677let categoryValue = systemSoundManager.TONE_CATEGORY_ALARM;
1678
1679let toneAttrs = systemSoundManager.createCustomizedToneAttrs();
1680toneAttrs.setTitle(title);
1681toneAttrs.setFileName(fileName);
1682toneAttrs.setCategory(categoryValue);
1683
1684let fd = 10; // 需更改为实际铃音fd,
1685let offset = 0; // 需更改为实际所需偏移量
1686let length = 50; // 需更改为实际所需数据长度
1687
1688let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1689systemSoundManagerInstance.addCustomizedTone(context, toneAttrs, fd, offset, length).then((value: string) => {
1690  console.info(`Promise returned to indicate that the value of tone uri in ringtone library.`);
1691}).catch ((err: BusinessError) => {
1692  console.error(`Failed to add customized tone ${err}`);
1693});
1694```
1695
1696### removeCustomizedTone<sup>12+</sup>
1697
1698removeCustomizedTone(context: BaseContext, uri: string): Promise&lt;void&gt;
1699
1700从铃音库中删除自定义铃音,使用Promise方式异步返回结果。
1701
1702**系统接口:** 该接口为系统接口。
1703
1704**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1705
1706**参数:**
1707
1708| 参数名 | 类型        | 必填 | 说明                                                                                                      |
1709|-----|-----------| ---- |---------------------------------------------------------------------------------------------------------|
1710| context  | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是   | 当前应用的上下文。                                                                                               |
1711| uri  | string    | 是   | 铃音uri,可通过[addCustomizedTone](#addcustomizedtone12)或[getAlarmToneAttrList](#getalarmtoneattrlist12)等方法获取 |
1712
1713**返回值:**
1714
1715| 类型                  | 说明                    |
1716|---------------------|-----------------------|
1717| Promise&lt;void&gt; | Promise回调返回设置成功或失败。 |
1718
1719**错误码:**
1720
1721以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
1722
1723| 错误码ID   | 错误信息              |
1724|---------| -------------------- |
1725| 201     | Permission denied. |
1726| 202     | Caller is not a system application. |
1727| 401     | The parameters check failed. |
1728| 5400102     | Operation is not allowed, e.g. ringtone to add is not customized. |
1729| 5400103 | I/O error. |
1730
1731**示例:**
1732
1733```ts
1734import { BusinessError } from '@kit.BasicServicesKit';
1735import { common } from '@kit.AbilityKit';
1736
1737let context: Context = getContext(this);
1738let uri = 'file://data/test.wav'; // 需更改为目标铃声文件的uri
1739
1740let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1741systemSoundManagerInstance.removeCustomizedTone(context, uri).then(() => {
1742  console.info(`Promise returned to indicate that the customized tone has been deleted.`);
1743}).catch ((err: BusinessError) => {
1744  console.error(`Failed to delete customized tone ${err}`);
1745});
1746```
1747
1748### getToneHapticsSettings<sup>13+</sup>
1749
1750getToneHapticsSettings(context: BaseContext, type: ToneHapticsType): Promise&lt;ToneHapticsSettings&gt;
1751
1752获取系统铃音的振动设置,使用Promise方式异步返回结果。
1753
1754**系统接口:** 该接口为系统接口。
1755
1756**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1757
1758**参数:**
1759
1760| 参数名 | 类型        | 必填 | 说明                                                                          |
1761|-----|-----------| ---- |----------------------------------------------------------------------------------|
1762| context  | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是   | 当前应用的上下文。   |
1763| type  | [ToneHapticsType](#tonehapticstype13)    | 是   | 待获取系统铃音的振动类型。 |
1764
1765**返回值:**
1766
1767| 类型                  | 说明                    |
1768|---------------------|-----------------------|
1769| Promise&lt;[ToneHapticsSettings](#tonehapticssettings13)&gt; | Promise回调返回铃声的振动设置。 |
1770
1771**错误码:**
1772
1773以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
1774
1775| 错误码ID   | 错误信息              |
1776|---------| -------------------- |
1777| 202     | Caller is not a system application. |
1778| 401     | The parameters check failed. |
1779| 5400103 | I/O error. |
1780| 20700003 | Unsupported operation. |
1781
1782**示例:**
1783
1784```ts
1785import { BusinessError } from '@kit.BasicServicesKit';
1786import { common } from '@kit.AbilityKit';
1787
1788let context: common.BaseContext = getContext(this);
1789let type: systemSoundManager.ToneHapticsType = systemSoundManager.RingtoneType.RINGTONE_TYPE_SIM_CARD_0;
1790
1791let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1792systemSoundManagerInstance.getToneHapticsSettings(context, type).then((value: systemSoundManager.ToneHapticsSettings) => {
1793  console.info(`Promise returned to indicate that the value of the tone haptics settings is obtained.`);
1794}).catch ((err: BusinessError) => {
1795  console.error(`Failed to get the tone haptics settings ${err}`);
1796});
1797```
1798
1799### setToneHapticsSettings<sup>13+</sup>
1800
1801setToneHapticsSettings(context: BaseContext, type: ToneHapticsType, settings: ToneHapticsSettings): Promise&lt;void&gt;
1802
1803设置系统铃音的振动,使用Promise方式异步返回结果。
1804
1805**系统接口:** 该接口为系统接口。
1806
1807**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1808
1809**参数:**
1810
1811| 参数名 | 类型        | 必填 | 说明                                                                          |
1812|-----|-----------| ---- |----------------------------------------------------------------------------------|
1813| context  | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是   | 当前应用的上下文。   |
1814| type  | [ToneHapticsType](#tonehapticstype13)    | 是   | 被设置的系统铃音的振动类型。 |
1815| settings  | [ToneHapticsSettings](#tonehapticssettings13)    | 是   | 被设置的系统铃音的振动设置。 |
1816
1817**返回值:**
1818
1819| 类型                  | 说明                    |
1820|---------------------|-----------------------|
1821| Promise&lt;void&gt; | Promise回调返回设置成功或失败。 |
1822
1823**错误码:**
1824
1825以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
1826
1827| 错误码ID   | 错误信息              |
1828|---------| -------------------- |
1829| 202     | Caller is not a system application. |
1830| 401     | The parameters check failed. |
1831| 5400102 | Operation is not allowed, e.g. ringtone to add is not customized. |
1832| 5400103 | I/O error. |
1833| 20700003 | Unsupported operation. |
1834
1835**示例:**
1836
1837```ts
1838import { BusinessError } from '@kit.BasicServicesKit';
1839import { common } from '@kit.AbilityKit';
1840
1841let context: common.BaseContext = getContext(this);
1842let type: systemSoundManager.ToneHapticsType = systemSoundManager.RingtoneType.RINGTONE_TYPE_SIM_CARD_0;
1843let toneHapticsSettings: systemSoundManager.ToneHapticsSettings = {
1844  mode: systemSoundManager.ToneHapticsMode.NON_SYNC,
1845  hapticsUri: '/data/storage/el2/base/haptics/synchronized/alarms/test.json', // 需更改为通过getToneHapticsList获取的Uri
1846}
1847
1848let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1849systemSoundManagerInstance.setToneHapticsSettings(context, type, toneHapticsSettings).then(() => {
1850  console.info(`Promise returned to indicate a successful setting of the tone haptics.`);
1851}).catch ((err: BusinessError) => {
1852  console.error(`Failed to set the tone haptics settings ${err}`);
1853});
1854```
1855
1856### getToneHapticsList<sup>13+</sup>
1857
1858getToneHapticsList(context: BaseContext, isSynced: boolean): Promise&lt;ToneHapticsAttrsArray&gt;
1859
1860获取同步或者非同步的系统铃音的振动属性列表,使用Promise方式异步返回结果。
1861
1862**系统接口:** 该接口为系统接口。
1863
1864**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1865
1866**参数:**
1867
1868| 参数名 | 类型        | 必填 | 说明                                                                          |
1869|-----|-----------| ---- |----------------------------------------------------------------------------------|
1870| context  | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是   | 当前应用的上下文。   |
1871| isSynced  | boolean    | 是   | 待获取的振动是否与某个铃音同步。 |
1872
1873**返回值:**
1874
1875| 类型                  | 说明                    |
1876|---------------------|-----------------------|
1877| Promise&lt;[ToneHapticsAttrsArray](#tonehapticsattrsarray13)&gt; | Promise回调返回同步或者非同步的系统铃音的振动属性列表。 |
1878
1879**错误码:**
1880
1881以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
1882
1883| 错误码ID   | 错误信息              |
1884|---------| -------------------- |
1885| 202     | Caller is not a system application. |
1886| 401     | The parameters check failed. |
1887| 5400103 | I/O error. |
1888| 20700003 | Unsupported operation. |
1889
1890**示例:**
1891
1892```ts
1893import { BusinessError } from '@kit.BasicServicesKit';
1894import { common } from '@kit.AbilityKit';
1895
1896let context: common.BaseContext = getContext(this);
1897
1898let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1899systemSoundManagerInstance.getToneHapticsList(context, false).then((value: systemSoundManager.ToneHapticsAttrsArray) => {
1900  console.info(`Promise returned to indicate that the value of the attribute list of tone haptics is obtained.`);
1901}).catch ((err: BusinessError) => {
1902  console.error(`Failed to get the attribute list of tone haptics ${err}`);
1903});
1904```
1905
1906### getHapticsAttrsSyncedWithTone<sup>13+</sup>
1907
1908getHapticsAttrsSyncedWithTone(context: BaseContext, toneUri: string): Promise&lt;ToneHapticsAttrs&gt;
1909
1910获取与指定铃音同步的振动属性,使用Promise方式异步返回结果。
1911
1912**系统接口:** 该接口为系统接口。
1913
1914**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1915
1916**参数:**
1917
1918| 参数名 | 类型        | 必填 | 说明                                                                          |
1919|-----|-----------| ---- |----------------------------------------------------------------------------------|
1920| context  | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是   | 当前应用的上下文。   |
1921| toneUri  | string    | 是   | 待获取同步振动的系统铃声Uri,可通过[getRingtoneAttrList](#getringtoneattrlist12)或[getSystemToneAttrList](#getsystemtoneattrlist12)等获取。 |
1922
1923**返回值:**
1924
1925| 类型                  | 说明                    |
1926|---------------------|-----------------------|
1927| Promise&lt;[ToneHapticsAttrs](#tonehapticsattrs13)&gt; | Promise回调返回与指定铃音同步的振动属性。 |
1928
1929**错误码:**
1930
1931以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
1932
1933| 错误码ID   | 错误信息              |
1934|---------| -------------------- |
1935| 202     | Caller is not a system application. |
1936| 401     | The parameters check failed. |
1937| 5400102 | Operation is not allowed, e.g. ringtone to add is not customized. |
1938| 5400103 | I/O error. |
1939| 20700003 | Unsupported operation. |
1940
1941**示例:**
1942
1943```ts
1944import { BusinessError } from '@kit.BasicServicesKit';
1945import { common } from '@kit.AbilityKit';
1946
1947let context: common.BaseContext = getContext(this);
1948let toneUri: string = '/data/storage/el2/base/RingTone/alarms/test.ogg'; // 需更改为实际铃音uri
1949
1950let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
1951systemSoundManagerInstance.getHapticsAttrsSyncedWithTone(context, toneUri).then((value: systemSoundManager.ToneHapticsAttrs) => {
1952  console.info(`Promise returned to indicate that the value of the attribute of tone haptics is obtained.`);
1953}).catch ((err: BusinessError) => {
1954  console.error(`Failed to get the attribute of tone haptics ${err}`);
1955});
1956```
1957
1958### openToneHaptics<sup>13+</sup>
1959
1960openToneHaptics(context: Context, hapticsUri: string): Promise&lt;number&gt;
1961
1962打开系统铃音的振动,使用Promise方式异步返回结果。
1963
1964**系统接口:** 该接口为系统接口。
1965
1966**系统能力:** SystemCapability.Multimedia.SystemSound.Core
1967
1968**参数:**
1969
1970| 参数名   | 类型       | 必填 | 说明                                                                                  |
1971| -------- | ---------| ---- |-------------------------------------------------------------------------------------|
1972| context  | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是   | 当前应用的上下文。           |
1973| hapticsUri      | string   | 是   | 待打开系统铃音的振动的uri,资源支持可参考[media.AVPlayer](../apis-media-kit/js-apis-media.md#avplayer9)。 |
1974
1975**返回值:**
1976
1977| 类型                    | 说明             |
1978|-----------------------|----------------|
1979| Promise&lt;number&gt; | Promise回调返回fd。 |
1980
1981**错误码:**
1982
1983以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)。
1984
1985| 错误码ID | 错误信息              |
1986| ------- | --------------------- |
1987| 202 | Caller is not a system application. |
1988| 401 | The parameters check failed. |
1989| 5400102 | Operation is not allowed, e.g. ringtone to add is not customized. |
1990| 5400103 | I/O error. |
1991| 20700003 | Unsupported operation. |
1992
1993**示例:**
1994
1995```ts
1996import { BusinessError } from '@kit.BasicServicesKit';
1997import { common } from '@kit.AbilityKit';
1998
1999let context: Context = getContext(this);
2000let hapticsUri = '/data/storage/el2/base/haptics/synchronized/alarms/test.json'; // 需更改为目标统铃音的振动的uri
2001
2002let systemSoundManagerInstance: systemSoundManager.SystemSoundManager = systemSoundManager.getSystemSoundManager();
2003systemSoundManagerInstance.openToneHaptics(context, hapticsUri).then((value: number) => {
2004  console.info(`Promise returned to indicate the value of fd.`);
2005}).catch ((err: BusinessError) => {
2006  console.error(`Failed to open haptics ${err}`);
2007});
2008```
2009
2010## RingtonePlayer<sup>10+</sup>
2011
2012type RingtonePlayer = _RingtonePlayer;
2013
2014系统铃音播放器对象。
2015
2016**系统能力:** SystemCapability.Multimedia.SystemSound.Core
2017
2018| 类型              |说明     |
2019|-----------------|-------|
2020| _RingtonePlayer | 系统铃音播放器。 |
2021
2022## SystemTonePlayer<sup>11+</sup>
2023
2024type SystemTonePlayer = _SystemTonePlayer;
2025
2026系统提示音播放器对象。
2027
2028**系统能力:** SystemCapability.Multimedia.SystemSound.Core
2029
2030| 类型              | 说明        |
2031|-----------------|-----------|
2032| _SystemTonePlayer | 系统提示音播放器。 |
2033
2034## RingtoneOptions<sup>10+</sup>
2035
2036type RingtoneOptions = _RingtoneOptions;
2037
2038系统铃音播放器配置项。
2039
2040**系统能力:** SystemCapability.Multimedia.SystemSound.Core
2041
2042| 类型              | 说明          |
2043|-----------------|-------------|
2044| _RingtoneOptions | 系统铃音播放器配置项。 |
2045
2046## SystemToneOptions<sup>11+</sup>
2047
2048type SystemToneOptions = _SystemToneOptions;
2049
2050系统提示音播放器配置项。
2051
2052**系统能力:** SystemCapability.Multimedia.SystemSound.Core
2053
2054| 类型              | 说明            |
2055|-----------------|---------------|
2056| _SystemToneOptions | 系统提示音音播放器配置项。 |
2057
2058
2059
2060