3

My app is for an important part dealing with Instant Messaging and receives FCM notifications. How can the app wake up for a few seconds upon reception of a High Importance notification, do a short fetch from the server and go back to its previous state. I have seen a lot of theoretical explanations but no real example of source code to achieve that. Can somebody help?

men
  • 131
  • 1
  • 9

1 Answers1

2
  1. Extend FirebaseMessagingService and get the message payload in onMessageReceived. (basic JSON parsing)
  2. Then, schedule a job to be executed instantly using Firebase JobDispatcher (code to schedule is in the repo itself) or the new WorkManager.
  3. Call the network request from the job.
Aditya
  • 33
  • 6
  • Thanks. I tried JobDispatcher and experienced some troubles, but it worked just fine with WorkManager. Hoping that the current version is stable. – men Dec 30 '18 at 07:42