Android Notification defaults

时间:2017-08-13 13:47:59

标签: android notifications android-notifications

I've used the newer NotificationCompat.builder, with NotificationChannel, and I was able to show a notification correctly (also in Android O).

The Android Documentation says to set a style which I've done with:

android.support.v4.app.NotificationCompat.InboxStyle

But the notification is showing with no sound, no vibrate and no flashing the light.

My question is: there is a simple way to set users default configuration for notifications? I am not looking for custom sound, vibrate and lights. I just wanna to support the default configurations.

The complete code

Notification notification = new Notification.Builder(context, channelId)
     .setContentTitle(contentTitle)
     .setContentText(contenteText)
     .setSmallIcon(R.drawable.ic_notfication)
     .setStyle(new Notification.InboxStyle())
     .build();

Any solution for this?

3 个答案:

答案 0 :(得分:0)

使用@ManyToOne方法管理震动,声音和光线行为

要启用set setDefaults(param)作为参数,请禁用Notification.DEFAULT_ALL。您可以通过自己的参数标志

设置每个可视化元素

答案 1 :(得分:0)

要在通知中设置默认的振动和灯光配置:

setDefaults(param)

设置默认声音配置:

RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)

答案 2 :(得分:-1)

This worked for me:

Uri defaultUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

and then use ther Notification-Builder's setSound(Uri uri)-method