/**
* Oreo不用Priority了,用importance
* IMPORTANCE_NONE 关闭通知
* IMPORTANCE_MIN 开启通知,不会弹出,但没有提示音,状态栏中无显示
* IMPORTANCE_LOW 开启通知,不会弹出,不发出提示音,状态栏中显示
* IMPORTANCE_DEFAULT 开启通知,不会弹出,发出提示音,状态栏中显示
* IMPORTANCE_HIGH 开启通知,会弹出,发出提示音,状态栏中显示
*/
public static void shouldNotification(MessageEntity messageEntity) {
//获取NotificationManager实例
NotificationManager mManager = (NotificationManager) App.getInstance().getSystemService(Context.NOTIFICATION_SERVICE);
Notification.Builder builder = null;
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
String name = messageEntity.getGroupName();
String content = "";
if (messageEntity.getChatType() == Constant.CHAT_TYPE_SINGLE) {//单聊
name = "好友昵称:"+ messageEntity.getRemarkName();
content = messageEntity.getContent();
} else {
name = "群昵称:"+ messageEntity.getGroupName();
content = "群成员昵称:"+ messageEntity.getRemarkName() + ":" + messageEntity.getContent();
}
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.O){
builder = new Notification.Builder(App.getInstance());
}else{
NotificationChannel notificationChannel = new
NotificationChannel("default", "IM", NotificationManager.IMPORTANCE_HIGH); //如果这里用IMPORTANCE_NOENE就需要在系统的设置里面开启渠道, //通知才能正常弹出
mManager.createNotificationChannel(notificationChannel);
builder = new Notification.Builder(App.getInstance(),"default");
}
builder.setSmallIcon(R.mipmap.ic_launcher)
//设置通知标题
.setContentTitle(name)
.setContentText(content)
.setLights(0xFF0000, 3000, 3000)
.setDefaults(Notification.DEFAULT_SOUND);
//调用系统多媒体裤内的铃声
//.setSound(Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI,"2"))
//.setSound(uri)
//调用自己提供的铃声,位于 /res/values/raw 目录下
//.setSound(Uri.parse("android.resource://com.littlejie.notification/" + R.raw.sound));
//设置通知内容
//设置通知时间,默认为系统发出通知的时间,通常不用设置
//.setWhen(System.currentTimeMillis());
//通过builder.build()方法生成Notification对象,并发送通知,id=1
mManager.notify(1, builder.build());
//Notification notification = builder.build();
//设置 Notification 的 flags = FLAG_NO_CLEAR
//FLAG_AUTO_CANCEL 表示该通知能被状态栏的清除按钮给清除掉
//等价于 builder.setAutoCancel(true);
//notification.flags |= Notification.FLAG_AUTO_CANCEL;
//mNotificationManager.notify(1, notification);
}
https://www.cnblogs.com/rchao/p/9057473.html
https://blog.csdn.net/fzkf9225/article/details/81119780
https://blog.csdn.net/androidzmm/article/details/80679804
https://blog.csdn.net/wangdan_ok/article/details/82866435 8.0以上Notification不显示问题以及声音关闭问题
https://blog.csdn.net/weixin_42695485/article/details/81463043 NotificationManager 通知声音控制逻辑
https://blog.csdn.net/fzkf9225/article/details/81119780 关于Android 8.0后notification通知声音无法关闭或开启的问题
https://www.cnblogs.com/cw828/p/10110944.html html调用安卓提示音报错E/MediaPlayerNative: error(-38, 0),E/MediaPlayerNative: error(1, -19)
MediaPlayer mediaPlayer = MediaPlayer.create(App.getInstance(), R.raw.office);
mediaPlayer.start();
mediaPlayer.reset();
mediaPlayer.release();