Created
February 10, 2024 17:50
-
-
Save Ayush783/7eb63415abc124f4f2c30c3bef5b955a to your computer and use it in GitHub Desktop.
Push notification retrigger worker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PushNotificationSchedulerWork(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) { | |
val tag = "PushNotificationSchedulerWork" | |
@RequiresApi(Build.VERSION_CODES.O) | |
override fun doWork(): Result { | |
try { | |
val context = applicationContext | |
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager | |
val activeNotifications = notificationManager.activeNotifications | |
for (notification in activeNotifications) { | |
// Your re-trigger function | |
reTriggerNotification(context, notification, notification.notification.channelId, notificationManager) | |
} | |
} catch (e: Exception) { | |
return Result.failure() | |
} | |
return Result.success() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment