简体   繁体   中英

How to send notification to specific user from web application to mobile application

I have a web application and mobile application to manage user parcels. Now, i want when a user receives a parcel, send a notification from web application to him on mobile application.

I used OneSignal and connected my mobile app successfully, but don't know which and how call an api to send notification to specific user?

Also, I read the documentation, but couldn't find any way and example for this requirement

The most popular way to send push notification to mobile devices is by using Google Firebase push notification .

Every device is tracked by unique device token generated by Firebase ( Android or iOS ).

Solution for your Usecase:

  • Whenever user tries to login into your application just trigger an API call to backend.

  • That API will put an entry to the database with userId and device token.

  • When you going to send push notification just get the device token from the database based on userId using Firebase SDK.

Example:

To send notification for multiple device ids that may be Android or IOS.

You can use MulticastMessage in fireBase.

                    MulticastMessage multiCast = MulticastMessage.builder()
                        .putAllData(new HashMap<String, String>() { put("message":"hi"); })
                        .setApnsConfig(ApnsConfig.builder().build())
                        .setAndroidConfig(AndroidConfig.builder().build())
                        .addAllTokens(Arrays.asList("devicetoken1", "devicetoken2"))
                        .build();

For reference : https://firebase.google.com/docs/cloud-messaging/send-message

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM