Ste*_*fMa 122 notifications android uri
我使用Notification.Builder来构建通知.现在我想使用默认声音通知:
builder.setSound(Uri sound)
但是Uri在默认通知中的位置是什么?
ρяσ*_*я K 261
尝试使用RingtoneManager获取默认通知Uri为:
Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
builder.setSound(uri);
For*_*ega 45
builder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI) 也有效
Jor*_*sys 27
Default Notification Sound是:mBuilder.setDefaults(Notification.DEFAULT_SOUND);
或使用RingtoneManager类:
mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
对于系统默认通知
Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
对于自定义通知
Uri customSoundUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.twirl);
通知声音的来源(我重命名为“twirl”并放置在 res->raw 文件夹中)
https://notificationsounds.com/message-tones/twirl-470
通知生成器:
NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(this)
                        .setSmallIcon(R.drawable.notificaion_icon)
                        .setContentTitle("Title here")
                        .setContentText("Body here")
                        .setSound(defaultSoundUri)
                        .setAutoCancel(true);
NotificationManager mNotifyMgr =
                (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotifyMgr.notify(id, mBuilder.build());
| 归档时间: | 
 | 
| 查看次数: | 76515 次 | 
| 最近记录: |