我正在尝试setLightColor使用从 JavaScript 接口返回的颜色进行更改。不幸的是,NotificationCompat.Builder(context, CHANNEL_ID).setLights对 API >= 26 绝对没有影响,所以我不能使用Intent.putExtra或类似的东西。
设置好之后还能改吗?我希望它是动态的。
编辑对我想要的东西似乎有一些误解。我不想碰那个Broadcast Reciever。它工作得很好。我想更改通知渠道。它不更新setLightColor(Color.___)。
在 protected void onCreate
String jobColor = someColor; // Will be filled in by other code - different colour every time
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "Channel_Name";
String description = "Channel_Description";
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
channel.setDescription(description);
channel.enableLights(true);
channel.setLightColor(Color.parseColor(jobColor)); // Dynamically set from above
channel.enableVibration(true);
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
我的 BroadcastReciever -我相信 setLight 不适用于 API 26 或更高版本
public class AlarmReceiver extends BroadcastReceiver {
private final String CHANNEL_ID = "some_channel";
@Override
public void onReceive(Context context, Intent intent) {
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0 , new Intent(context, MainPage.class), 0);
String jobColor = intent.getStringExtra("jobColor");
}
}
holdtom
茅侃侃
相关分类