Zaylour 2018-06-07 00:55 采纳率: 69.2%
浏览 2758
已结题

安卓的notification通知,在5.1.1的系统中,通知横幅没显示出来,直接就跳到主界面了

这是一个聊天软件,有新的信息时会弹出横幅通知,但是在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{

    }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程
    • ¥15 redis-full-check比较 两个集群的数据出错
    • ¥15 Matlab编程问题
    • ¥15 训练的多模态特征融合模型准确度很低怎么办
    • ¥15 kylin启动报错log4j类冲突
    • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
    • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
    • ¥15 onvif+openssl,vs2022编译openssl64
    • ¥15 iOS 自定义输入法-第三方输入法