-
Notifications
You must be signed in to change notification settings - Fork 4
Handle Push Notifications
kristiyan-petrov edited this page Feb 27, 2024
·
11 revisions
We highly recommend to add push notification to your app in oder to receive incoming calls even when the app is killed.
- Doze mode requires highPriority in FCM (Android 6.0+) for more info
- In China FCM does not work (you can use Pushy, Baidu or similar services)
- Chinese mobile phones(Huawei, Xiaomi, Oppo, Vivo, LeTV, IQOO, Asus, ...) have security settings that need to be handled by the end-user. You should show a dialog to tell the user that the application will need autoBoot, notifications shown, shown on lock-screen and power optimizations. This settings may not be required if your app is already in the white-list of the PlayStore and Chinese producers. You may find useful the following links
- Listen server-side for webhook coming from KaleyraVideo.
(Discover how your backend can be notified with upcoming call events registering event hook on_call_incoming here: https://developers.kaleyra.io/reference/video-v2-webhook-post).
- Forward the data you have received via the webhook to your Android Application with a push notification framework of your choice (FCM, OneSignal or others)
- Implement your client listener for notifications (FCM, OneSignal or any others) depends on the notification framework you have decided to use.
- Once received the notification you will need to give the payload of the notification to our SDK. In case your application handles different types of notifications be sure to forward only the payload meant for our SDK (the one you have received from the webhook)
Incoming calls and chat messages push notification payloads can be passed to the BandyerSDK object as shown below. Be sure to connect the BandyerSDK instance before.
AccessTokenProvider accessTokenProvider = new AccessTokenProvider() {
@Override
public void provideAccessToken(@NonNull String userId, @NonNull Completion<String> completion) {
// retrieve token [...]
completion.success(accessToken); // or call completion.error(exception) if an error occurred during token retrieval process
}
};
Session session = new Session(
"userId",
accessTokenProvider,
sessionObserver);
BandyerSDK.getInstance().connect(
session,
errorReason -> Log.e(TAG, "Unable to connect BandyerSDK with error: " + errorReason)
);
BandyerSDK.getInstance().handleNotification(payload);
The push notification payload received by your app is just a simple json containing the information your server sent to FCM.
{
"event":"on_call_incoming",
"room_id":"room_f61b4d202472",
"data":{
"initiator":"usr_123",
"users":[
{
"user":{
"userAlias":"usr_123"
},
"status":"invited"
},
{
"user":{
"userAlias":"usr_999"
},
"status":"invited"
}
],
"roomAlias":"room_f61b4d202472",
"options":{
"duration":0,
"record":true,
"recordingType":"automatic",
"recording":"automatic",
"creationDate":"2022-05-26T09:04:38.097Z",
"callType":"audio_upgradable",
"live":true
}
}
}