这是一个聊天软件,有新的信息时会弹出横幅通知,但是在5.1系统的华为手机中,没有显示横幅,直接就跳到聊天页面了,正常来说应该是用户点击了通知才进入到聊天页面的,结果我用另一台手机,发送一个新的消息,在这台华为5.1.1的手机上就直接进入了主页面,没有横幅通知显示。
var manager=context.getSystemService(NOTIFICATION_SERVICE) as NotificationManager
var mUri= Settings.System.DEFAULT_NOTIFICATION_URI
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
{
var mChannel= NotificationChannel("1", "hh", NotificationManager.IMPORTANCE_LOW)
mChannel.setDescription("description of this notification");
mChannel.setSound(mUri, Notification.AUDIO_ATTRIBUTES_DEFAULT);
mChannel.enableVibration(true)
mChannel.enableLights(true)
mChannel.vibrationPattern = longArrayOf(100, 200, 300, 400, 500, 400, 300, 200, 400)
manager.createNotificationChannel(mChannel);
}
var intent= Intent(context, MainActivity::class.java)
var pi =PendingIntent.getActivity(context,1,intent,PendingIntent.FLAG_UPDATE_CURRENT)//PendingIntent.FLAG_UPDATE_CURRENT Intent.FLAG_ACTIVITY_NEW_TASK
if(NotificationManagerCompat.from(context).areNotificationsEnabled()){
if(context!=null){
var notification= NotificationCompat.Builder(context,"1")
notification.setContentTitle("通知")
notification .setContentText(neirong)
notification .setSmallIcon(R.drawable.notifytubiao)
Log.e("xinxi","当前sdk版本:"+Build.VERSION.SDK_INT)
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){//悬挂式Notification,5.0后显示
notification.setCategory(NotificationCompat.CATEGORY_MESSAGE);
notification.setVisibility(Notification.VISIBILITY_PUBLIC);
notification .setNumber(15)
notification .setFullScreenIntent(pi, true)
}
notification.setLargeIcon(BitmapFactory.decodeResource(Resources.getSystem(),R.drawable.ic_launcher))
notification.setWhen(time)//System.currentTimeMillis()
notification .setPriority(NotificationCompat.PRIORITY_DEFAULT);
notification.setLights(0xff00ff00.toInt(), 3000, 1000);
notification.setAutoCancel(true)
notification .setChannelId("1")
notification .setNumber(15)
notification.setContentIntent(pi)
// notification.setDefaults(NotificationCompat.DEFAULT_ALL);//闪灯
manager.notify(1, notification .build())
}
}else{
}