我想smallIcon
在前台服务运行时更改状态栏中的通知,具体取决于该服务收集的状态,即“静音”或“取消静音”。
smallIcons
从res.drawable
资源显示替代内容需要什么?
在服务类的initialize方法中,我目前将静音图标设置如下,但是在启动服务后我不知道如何更改它:
NotificationCompat.Builder builder = new NotificationCompat.Builder(
this, NOTE_CHANNEL_ID)
.setSmallIcon(R.drawable.mute_icon)
.setContentTitle("Calm: Running")
.setContentText(this.getString(R.string.calm_close_txt))
.setOngoing(true)
.setContentIntent(stopIntent);
startForeground(NOTIFICATION_ID, builder.build());
您只需要保存对的引用NotificationCompat.Builder
。然后使用的notify(int id, Notification notification)
方法NotificationManagerCompat
。
例:
NotificationCompat.Builder notificationBuilder;
private void startNotif(){
notificationBuilder = new NotificationCompat.Builder(
this, NOTE_CHANNEL_ID)
.setSmallIcon(R.drawable.mute_icon)
.setContentTitle("Calm: Running")
.setContentText(this.getString(R.string.calm_close_txt))
.setOngoing(true)
.setContentIntent(stopIntent);
startForeground(NOTIFICATION_ID, notificationBuilder.build());
}
private void changeIcon(int resID, Context context){
notificationBuilder.setSmallIcon(resID);
NotificationManagerCompat notificationManagerCompat =
NotificationManagerCompat.from(context);
notificationManagerCompat.notify(NOTIFICATION_ID, notificationBuilder.build());
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句