Oreo - Blinking the notification LED

问题: in oreo how to enable notification led blink without notification sound,if i disable notification sound led does not blink Notification notification = new NotificationC...

问题:

in oreo how to enable notification led blink without notification sound,if i disable notification sound led does not blink

  Notification notification = new NotificationCompat.Builder(this)
            .setLights(0xff00ff00, 3000, 100)
          //  .setContentTitle("title")
            .setSmallIcon(R.drawable.cubs)
            .setOngoing(false)
            .setSound(null)
            .setPriority(Notification.PRIORITY_MAX).build();
    NotificationManager notificationManager =
            (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(notification_id, notification);

回答1:

From Oreo, the mechanism of NotificationChannel was introduced. You must set the channel and enable lights like this,

NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    CharSequence name = "Notification";
    String description = "Notification";
    int importance = NotificationManager.IMPORTANCE_DEFAULT;
    NotificationChannel mChannel = new NotificationChannel("someChannelID", name, importance);
    mChannel.setDescription(description);
    mChannel.setShowBadge(true);
    mChannel.enableLights(true);
    mChannel.setLightColor(Color.RED);
    mChannel.setSound(uri);
    if (notificationManager != null)  notificationManager.createNotificationChannel(mChannel);
    Notification notification = new Notification.Builder(context, "someChannelID")
            .setContentTitle(contentTitleText)
            .setContentText(contentContentText)
            .setNumber(1)
            .setSmallIcon(whiteLogo)
            .setBadgeIconType(whiteLogo)
            .setAutoCancel(true)
            .setContentIntent(pendingIntent)
            .build();
    if (notificationManager != null) {
        notificationManager.notify(notification_id, notification);
    }
}

else {
    NotificationCompat.Builder notification = new NotificationCompat.Builder(this)
            .setSmallIcon(whiteLogo)
            .setLargeIcon(largeIcon)
            .setContentTitle(contentTitleText)
            .setContentText(contentContentText)
            .setOngoing(false)
            .setNumber(1)
            .setPriority(NotificationCompat.PRIORITY_DEFAULT)
            .setAutoCancel(true)
            .setLights(colorPPDOrange, 1000, 2000);
            .setSound(uri);
            .setContentIntent(pendingIntent)
            .build();
    if (notificationManager != null) {
        notificationManager.notify(notification_id, notification);
    }
}
  • 发表于 2019-01-09 22:45
  • 阅读 ( 198 )
  • 分类:网络文章

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除