Firebase Messaging not Working in Modern Android Instant App - DisplayNotificationRequired?

Viewed 626

I've read all the related SO questions, most of which were asked in answered in 2017 or early 2018, before Google simplified the way Instant Apps could be created. In my case, I created an "instant enabled app bundle" (described here) that works both as an app and as an instant app.

The app bundle includes a library I wrote that is configured to receive Firebase messages (described here) from the AWS Simple Notification Service (SNS). The problem is that messages are received when the app is run, but not received when the instant app is run.

The good news is that when I look at the AWS CloudWatch console, I can see every failed attempt. Here is the relevant part of the message:

"providerResponse": "{\"results\":[{\"error\":\"InvalidParameters: DisplayNotificationRequired\"}],\"multicast_id\":\"8198293557962051\",\"success\":0,\"failure\":1,\"canonical_ids\":0}"

The message content is:

{
"to" : "fi_Pclw7RrWtPm0xMVSgbC:APA91bGJFzM6RQVisO0N_JOAb8rUOKBVPZ0I5jh9Vf-4f-xXtbQY_Ik7q3wLGeCbR5bh_lFWDy0PX-F2mIlamMlCTIuEqEOlk0KcFO9a5fYk6B_omGqevjY6KNiByI5j_vKQaF17Rif8",
 "data" : {
     "body" : "Content message",
     "title": "the Title",  
     "key_1" : "Value for key_1",
     "key_2" : "Value for key_2"
     }
}

I've searched for the DisplayNotificationRequired error but can't find anything. Anyone know what this means and how to fix? Thanks!


Since I wrote the above, I tried adding a notification object as well:

{
"to" : "fi_Pclw7RrWtPm0xMVSgbC:APA91bGJFzM6RQVisO0N_JOAb8rUOKBVPZ0I5jh9Vf-4f-xXtbQY_Ik7q3wLGeCbR5bh_lFWDy0PX-F2mIlamMlCTIuEqEOlk0KcFO9a5fYk6B_omGqevjY6KNiByI5j_vKQaF17Rif8",
    "notification" : {
     "body" : "Content message",
     "title": "the Title"
     },
 "data" : {
     "body" : "Content message",
     "title": "the Title",  
     "key_1" : "Value for key_1",
     "key_2" : "Value for key_2"
     }
}

Now I'm getting an error with MissingDataUri instead of a DisplayNotificationRequired error. When I use Postman to send this message directly to the device token, I also get a MissingDataUri error, so I'm thinking this is not a AWS SNS or a Firebase Cloud Messaging issue, but just an instant app issue.

Finally, I understand that there was an "instant app notifications beta" way back in 2018 that appears to be still running: https://g.co/instantapps/notifications

Is it still not possible to send a push notification to an instant app, specifically with a 'data' payload? (I went ahead an submitted the form...just in case.)

Thanks all!

1 Answers

The only way you can do it is with a notification attached to a foreground service. Remote notifications are currently not possible with instant apps.

Can I ask why you want to do it? An instant app should deliver an instant experience and you should assume that the user will either install the full version, or abandon it after closing the app. So remote notifications does not make much sense, unless it is attached to the "experience" the user is expecting.

If a notification flow is necessary for the experience, you should use a foreground service. A good example could be if you buy a drop-in service that has a queue (hairdresser for example) and you want to notify the user during the waiting time. In this case you could create a foreground service with an attached notification. The service polls your backend in the background to get a time estimate and queue position, and then update the notification accordingly. When the user is finished with his haircut, you can close the foreground service and thus allowing the app to be removed from the device automatically.

Read more about services: https://developer.android.com/guide/components/services

You will need: https://developer.android.com/reference/android/Manifest.permission#INSTANT_APP_FOREGROUND_SERVICE

Related