2

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!

ScottyB
  • 2,167
  • 1
  • 30
  • 46

1 Answers1

2

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

Torkel Velure
  • 1,217
  • 10
  • 17
  • 1
    Thanks Torkel. I have native version of my app for both iOS and Android. I got excited about iOS App Clips which allows push notifications "for eight hours" by default, and was hoping I could do the same thing with an Android Instant App. The app is generally for single-use with a large number of people, but requires a relatively quick push notification and I really don't want to poll my servers. I found this: https://www.reddit.com/r/androiddev/comments/bkuhre/possible_to_run_firebasemessagingservice_from_a/ which might be the answer. Thoughts? – ScottyB Sep 04 '20 at 21:11
  • 1
    Also found this: https://stackoverflow.com/questions/50317159/enable-push-notifications-on-instant-app which says there was a beta program in 2018 for this. I applied 5 days ago but haven't heard back. I figured it was out of beta by now! – ScottyB Sep 04 '20 at 21:13
  • I researched the same thing a couple months ago and ended up doing the polling solution. Please tell if you have find something else! – Torkel Velure Sep 04 '20 at 21:27
  • Did you try to sign up for the beta program? They should take down the form if it’s no longer going on. I may dig into creating a firebase messaging service in a foreground service. – ScottyB Sep 04 '20 at 21:42
  • Never bothered with it since it was so old. Found this though: https://stackoverflow.com/questions/58022896/service-to-keep-alive-firebasemessagingservice-even-if-app-is-not-running-and-sh – Torkel Velure Sep 04 '20 at 21:53
  • 1
    Well I'm still not convinced it's not possible to send push notifications if the app is an Instant App! My service launches just fine with no errors. I start it with code and I've also started it automatically. I can't find anything states it's not possible, and we can't be the only two people in the last 3 years who've tried! I even started using https://github.com/onmyway133/PushNotifications to rule out everything else, with no luck. I'll award you the bounty if nothing else turns up... – ScottyB Sep 06 '20 at 20:52
  • The documentation says "In addition, instant-enabled app bundles cannot do the following: Use background services. Send notifications when running in the background". https://developer.android.com/topic/google-play-instant/getting-started/instant-enabled-app-bundle#request-supported-permissions – Torkel Velure Sep 06 '20 at 21:05
  • 1
    Thanks. I briefly hoped I might be able to use Firebase Messaging for web apps (https://firebase.google.com/docs/cloud-messaging/js/client) using an Android webview but, alas, Android webviews don't support the required Push API. iOS webviews don't either, but at least App Clips do! As a developer who wrote and maintains the same native app on both platforms, I generally find things easier with iOS documentation, IDE, and implementation to do the same thing... – ScottyB Sep 08 '20 at 14:04
  • Anyone here tried to use PWA in android instant apps for push notification? – sean May 18 '23 at 03:42