Skip to content

Instantly share code, notes, and snippets.

@Ayush783
Created February 10, 2024 17:50
Show Gist options
  • Save Ayush783/7eb63415abc124f4f2c30c3bef5b955a to your computer and use it in GitHub Desktop.
Save Ayush783/7eb63415abc124f4f2c30c3bef5b955a to your computer and use it in GitHub Desktop.
Push notification retrigger worker
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