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 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 有没有帮写代码做实验仿真的
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥30 vmware exsi重置后登不上
    • ¥15 易盾点选的cb参数怎么解啊
    • ¥15 MATLAB运行显示错误,如何解决?
    • ¥15 c++头文件不能识别CDialog
    • ¥15 Excel发现不可读取的内容
    • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题