From 027b356357aa2c62ab965d96daf821e1a9d7dc7a Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Tue, 15 Sep 2020 19:25:32 +0900 Subject: [PATCH] Fix recurring alert sound if notification not tapped --- .../services/ActivityCheckerService.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/services/ActivityCheckerService.java b/app/src/main/java/awais/instagrabber/services/ActivityCheckerService.java index fb01201c..255d051c 100644 --- a/app/src/main/java/awais/instagrabber/services/ActivityCheckerService.java +++ b/app/src/main/java/awais/instagrabber/services/ActivityCheckerService.java @@ -9,6 +9,7 @@ import android.os.Handler; import android.os.IBinder; import android.text.TextUtils; +import androidx.annotation.NonNull; import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationManagerCompat; @@ -115,18 +116,24 @@ public class ActivityCheckerService extends Service { } private void showNotification(final String notificationString) { - final Intent intent = new Intent(getApplicationContext(), MainActivity.class) - .setAction(Constants.ACTION_SHOW_ACTIVITY) - .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); final Notification notification = new NotificationCompat.Builder(this, Constants.ACTIVITY_CHANNEL_ID) .setCategory(NotificationCompat.CATEGORY_STATUS) .setSmallIcon(R.drawable.ic_notif) .setAutoCancel(true) - .setPriority(NotificationCompat.PRIORITY_MIN) + .setOnlyAlertOnce(true) + .setPriority(NotificationCompat.PRIORITY_DEFAULT) .setContentTitle(getString(R.string.action_notif)) .setContentText(notificationString) - .setContentIntent(PendingIntent.getActivity(getApplicationContext(), 1738, intent, PendingIntent.FLAG_UPDATE_CURRENT)) + .setContentIntent(getPendingIntent()) .build(); notificationManager.notify(Constants.ACTIVITY_NOTIFICATION_ID, notification); } + + @NonNull + private PendingIntent getPendingIntent() { + final Intent intent = new Intent(getApplicationContext(), MainActivity.class) + .setAction(Constants.ACTION_SHOW_ACTIVITY) + .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); + return PendingIntent.getActivity(getApplicationContext(), 1738, intent, PendingIntent.FLAG_UPDATE_CURRENT); + } }