android - 在已删除通知倾斜的应用中获取重复通知
问题描述
在调试我的应用程序时,我得到了一个奇怪的输出。首先,当我运行应用程序时,警报时的通知标题是按照下面的代码,即 Dosing Alert!:
String banner="Time to dose your "+AType;
NotificationHelper notificationHelper=new NotificationHelper(this);
NotificationCompat.Builder
nb=notificationHelper.getChannel1Notification("Dosing Alert!",banner);
notificationHelper.getManager().notify(1,nb.build());
但在那之后,我收到了 2 条通知。一个标题为“剂量警报!” 另一个标题为“Dosing Alert”(缺少感叹号。这个标题是我一开始设置的,但后来我添加了感叹号)。我到处搜索这个问题,但不明白为什么会这样。
这是我的通知助手类。
public class NotificationHelper extends ContextWrapper {
public static final String channel1ID="channel1ID";
public static final String channel1IName="Just Plant Them";
private NotificationManager mManager;
public NotificationHelper(Context base) {
super(base);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createChannels();
}
}
@TargetApi(Build.VERSION_CODES.O)
public void createChannels() {
NotificationChannel channel1 = new NotificationChannel(channel1ID, channel1IName, NotificationManager.IMPORTANCE_HIGH);
channel1.enableLights(true);
channel1.enableVibration(true);
channel1.setLightColor(R.color.colorPrimary);
channel1.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
getManager().createNotificationChannel(channel1);
}
public NotificationManager getManager() {
if (mManager==null){
mManager=(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
}
return mManager;
}
public NotificationCompat.Builder getChannel1Notification(String title,String message){
return new NotificationCompat.Builder(getApplicationContext(),channel1ID)
.setContentTitle(title)
.setContentText(message)
.setAutoCancel(true)
.setSmallIcon(R.drawable.plant)
.setPriority(NotificationCompat.PRIORITY_MAX);
}
}
请帮我解决。
解决方案
推荐阅读
- ios - Delphi 未找到适用于 iOS 的配置文件
- ruby-on-rails - 用户注销时将签出时间更新到数据库中
- github - 删除原始存储库时分叉会发生什么?
- java - 为什么 HIbernate 的 PESEL 验证器不起作用?
- java - 当为位于 hdfs 位置的 jar 提供额外的类路径时,火花提交失败
- linux - 使用 sed - 如何用中间的未知内容替换两个 HTML 标记或模式?
- angular - 重构 *ngIf 容器
- list - 使用 Haskell 中的函数将列表列表与列表组合
- reactjs - React.memo() vs React 函数式组件
- jquery - 从ajax结果并排提升两个div