我用的是Notification.Builder建立一个通知。 现在我想使用默认的声音通知有:
builder.setSound(Uri sound)
但如果是开放的,以默认的通知?
我用的是Notification.Builder建立一个通知。 现在我想使用默认的声音通知有:
builder.setSound(Uri sound)
但如果是开放的,以默认的通知?
尝试使用RingtoneManager获得默认通知乌里为:
Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
builder.setSound(uri);
builder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
的作品,以及
Default Notification Sound
是: mBuilder.setDefaults(Notification.DEFAULT_SOUND);
或使用RingtoneManager类别:
mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
所有这些方法的工作
mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
mBuilder.setDefaults(Notification.DEFAULT_SOUND);
谷歌文档
您可以使用此还有:
Uri uri = Uri.parse(PreferenceManager.getDefaultSharedPreferences(this).
getString("pref_tone", "content://settings/system/notification_sound"));
mBuilder.setSound(uri);
对于系统默认的通知
URI URI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
对于自定义通知
URI customSoundUri = Uri.parse( “android.resource://” + getPackageName()+ “/” + R.raw.twirl);
通知声音的源(I重命名为“捻”并放置在水库>原始文件夹)
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());
如果有人仍然需要,这一点也适用声音和振动精绝。
Context context = getApplicationContext();
long[] vibrate = new long[] { 1000, 1000, 1000, 1000, 1000 };
Intent notificationIntent = new Intent(context, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context,
0, notificationIntent,
PendingIntent.FLAG_CANCEL_CURRENT);
Resources res = context.getResources();
Notification.Builder builder = new Notification.Builder(context);
builder.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.notif)
.setTicker("lastWarning")
.setWhen(System.currentTimeMillis())
.setAutoCancel(true)
.setVibrate(vibrate)
//.setContentTitle(res.getString(R.string.notifytitle))
.setContentTitle("Notification")
.setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
//.setContentText(res.getString(R.string.notifytext))
.setContentText("Notification text");
// Notification notification = builder.getNotification(); // until API 16
Notification notification = builder.build();
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFY_ID, notification);
如果您想禁用例如振动变化振动,新长[] {0,0,0,0,0}; 几乎类似的事情,你可以用声音做或者其他语句中使用。