[英]Android Notification Channel Pushes Older Unread Notifications With New Notifications
I'm new with the Android Notification Channel. 我是Android通知频道的新手。 I followed the tutorials from Google Dev docs about it, but I'm having some trouble when pushing notifications. 我遵循了Google Dev文档中的指南,但是在推送通知时遇到了一些麻烦。 My problem is, if I get a notification and swipe-cancel it or just don't click on it, the following notifications come with older swipe-cancelled or untouched notifications. 我的问题是,如果我收到通知并轻扫取消或只是不单击它,则以下通知与较旧的轻扫已取消或未更改的通知一起提供。 Notifications are increasing cumulatively. 通知正在累积增加。
My code is below: 我的代码如下:
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
String channelId = "some_channel_id";
CharSequence channelName = "Some Channel";
int importance = NotificationManager.IMPORTANCE_LOW;
NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName, importance);
notificationChannel.enableLights(true);
notificationChannel.setLightColor(Color.RED);
notificationChannel.enableVibration(true);
notificationChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
notificationManager.createNotificationChannel(notificationChannel);
int num = (int) System.currentTimeMillis();
Notification notification = new Notification.Builder(this)
.setContentTitle("Some Message")
.setContentText("You've received new messages!")
.setAutoCancel(true)
.setSmallIcon(R.drawable.fav_ico)
.setChannelId(channelId)
.build();
notificationManager.notify(num, notification);
Module Gradle : 模块摇篮
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.android.support:design:26.1.0'
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
compile "com.android.support:appcompat-v7:26.0.+"
compile 'com.google.firebase:firebase-core:12.0.1'
compile 'com.google.firebase:firebase-messaging:12.0.1'
compile 'org.apache.commons:commons-lang3:3.4'
compile 'id.zelory:compressor:2.1.0'
compile 'net.gotev:uploadservice:3.0'
compile 'dev.dworks.libs:volleyplus:+'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
apply plugin: 'com.google.gms.google-services'
Where am I making this mistake? 我在哪里犯这个错误?
try this code 试试这个代码
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel mChannel = new NotificationChannel(LOCATION_CHANNEL, LOCATION_NAME, importance);
mChannel.enableLights(false);
mChannel.enableVibration(false);
int id = getApplicationInfo().icon;
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, mChannel.getId())
.setSmallIcon(id)
.setContentTitle(getString(R.string.app_name))
.setContentText(getString(R.string.location_notification_text))
.setPriority(NotificationManager.IMPORTANCE_DEFAULT)
.setVibrate(new long[] {0L})
.setChannelId(mChannel.getId())
.setAutoCancel(true);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(pendingIntent);
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (manager != null) {
manager.createNotificationChannel(mChannel);
manager.notify(NOTIFICATION_ID, mBuilder.build());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.