android - 如何启用 android 的状态 LED 或更改其颜色?
问题描述
我搜索了它,但我无法弄清楚!
有一些答案,但它们不适用于Android 8.0或更高版本。
我在阿里巴巴和WhatsApp看到了这个功能!!
可以的话帮忙!这也可以帮助其他人。
我的代码:
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(getString(R.string.default_notification_channel_id), remoteMessage.getData().get("title"), NotificationManager.IMPORTANCE_DEFAULT);
channel.enableLights(true);
channel.setLightColor(0xff0000);
channel.shouldShowLights();
channel.canShowBadge();
notificationManager.createNotificationChannel(channel);
}
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "0")
.setSmallIcon(R.drawable.ic_notification)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_notification))
.setContentTitle(remoteMessage.getData().get("title"))
.setContentText(remoteMessage.getData().get("message"))
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setPriority(NotificationCompat.PRIORITY_MAX)
.setVibrate(new long[] {0, 1000, 200,1000 })
.setChannelId(getString(R.string.default_notification_channel_id))
.setLights(Color.RED, 100 , 100)
.setAutoCancel(true);
if (notificationManager != null) {
Notification notification = notificationBuilder.build();
notification.ledARGB = 0xFFff0000;
notification.flags = Notification.FLAG_SHOW_LIGHTS;
notification.ledOnMS = 100;
notification.ledOffMS = 100;
notificationManager.notify(new Random().nextInt(60000), notification);
}
解决方案
推荐阅读
- php - Laravel 安装程序在创建新项目时抛出错误
- android - android:nextFocusDown 在 viewpager 中不起作用
- php - 在heroku中播种数据透视表导致错误
- javascript - Javascript 错误地解码 unicode
- jquery - jQuery - 使用子 div 值对父 div 进行排序不起作用
- html - 如何创建带有外部圆形 div 的配置文件下拉菜单?
- javascript - 我们如何使用 Apache Echart.js 绘制直方图,并使用自定义工具提示突出显示单条?
- shopware - Shopware 6:如何从店面的存储库中加载类别
- javascript - 使用 Thingsboard 将图标动态放置在简单卡片中
- ios - MusicBrainz API 数据未在 UITableView 中显示