PatilShreyas / FCM-OnDeviceNotificationScheduler

Demo implementation to Schedule FCM Notifications on Android Device using AlarmManager + WorkManager.
MIT License
118 stars 28 forks source link
alarmmanager android fcm fcm-notifications firebase firebase-cloud-messaging kotlin kotlin-android workmanager

🔔 FCM - Push Notification Scheduler⏰ (On Device 📱)

Article About this is available here.

This is demo app to implement FCM On Device Push Notification Scheduling using AlarmManager and WorkManager.

Show some :heart: and star the repo to support the project

GitHub stars GitHub forks GitHub watchers GitHub followers Twitter Follow Medium Article License

Introduction

In this demo app, We are subscribing to a FCM Channel discount-offers. We'll receive Data payload from FCM to this subscribed channel and we will process and schedule it.

Dependencies

Setup

Implementation Structure

src
│
└───fcm
│   │   MyFirebaseMessagingService.kt
│   │   NotificationBroadcastReceiver.kt
│   │   ScheduledWorker.kt
│   
└───util
|   │   NotificationUtil.kt
|   │   SettingUtil.kt
|
└───ui
|   │   MainActivity.kt
|   

What's Happening? 🤔

Hurrah!😍 we have successfully implemented On-Device Scheduling of FCM Push Notification👍.

Let's Test It

I have sent below payload with to the FCM Channel (discount-offers).

{ 
 "to": "/topics/discount-offers", 
 "priority": "high",
 "data" : {
  "title" : "🎅 Christmas Offer 🎄",
  "message" : "Grab 90% Discount 😍 on Mobile Phones",
  "isScheduled" : "true",
  "scheduledTime" : "2019-12-13 14:12:00"
 }
}

🚀See output below and notice that Internet/Wi-Fi is OFF still at exactly 02:12 pm I'm getting a notification on the system tray 😃.

Yippie 😍! It's working as expected. Hope you liked that. If you find it helpful please share this. Maybe it'll help someone needy!

:heart: Found this project useful?

If you found this project useful, then please consider giving it a :star: on Github and sharing it with your friends via social media.

Sharing is Caring!

Connect With Me

If you want to contact me, feel free to reach me… Visit My Profile.

License

MIT License

Copyright (c) 2019 Shreyas Patil

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.