Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 173c879

Browse files
author
Elias Naur
committed
Use unique ID for notifications
1 parent 30983ab commit 173c879

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/com/alexbbb/uploadservice/UploadService.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class UploadService extends IntentService {
3131

3232
private static final String SERVICE_NAME = UploadService.class.getName();
3333

34+
private static final int UPLOAD_NOTIFICATION_ID = 1234; // Something unique
3435
private static final int BUFFER_SIZE = 4096;
3536
private static final String NEW_LINE = "\r\n";
3637
private static final String TWO_HYPHENS = "--";
@@ -354,27 +355,27 @@ private void createNotification() {
354355
.setContentText(notificationConfig.getMessage())
355356
.setSmallIcon(notificationConfig.getIconResourceID())
356357
.setProgress(100, 0, true);
357-
notificationManager.notify(0, notification.build());
358+
notificationManager.notify(UPLOAD_NOTIFICATION_ID, notification.build());
358359
}
359360

360361
private void updateNotificationProgress(final int progress) {
361362
notification.setContentTitle(notificationConfig.getTitle())
362363
.setContentText(notificationConfig.getMessage())
363364
.setSmallIcon(notificationConfig.getIconResourceID())
364365
.setProgress(100, progress, false);
365-
notificationManager.notify(0, notification.build());
366+
notificationManager.notify(UPLOAD_NOTIFICATION_ID, notification.build());
366367
}
367368

368369
private void updateNotificationCompleted() {
369370
if (notificationConfig.isAutoClearOnSuccess()) {
370-
notificationManager.cancel(0);
371+
notificationManager.cancel(UPLOAD_NOTIFICATION_ID);
371372
return;
372373
} else {
373374
notification.setContentTitle(notificationConfig.getTitle())
374375
.setContentText(notificationConfig.getCompleted())
375376
.setSmallIcon(notificationConfig.getIconResourceID())
376377
.setProgress(0, 0, false);
377-
notificationManager.notify(0, notification.build());
378+
notificationManager.notify(UPLOAD_NOTIFICATION_ID, notification.build());
378379
}
379380
}
380381

@@ -383,6 +384,6 @@ private void updateNotificationError() {
383384
.setContentText(notificationConfig.getError())
384385
.setSmallIcon(notificationConfig.getIconResourceID())
385386
.setProgress(0, 0, false);
386-
notificationManager.notify(0, notification.build());
387+
notificationManager.notify(UPLOAD_NOTIFICATION_ID, notification.build());
387388
}
388389
}

0 commit comments

Comments
 (0)