I am trying to provide a native video calling experience with Twilio Video Call. Here is the scenario:
- Person AAA calls person BBB.
- Person BBB does not have the app open, in the background or foreground, app is in killed state, phone may even be locked.
- When a call from AAA arrives, the app is opened with a video ui with an answer button. Just like in WhatsApp, Google Duo, Skype...
We have FCM in place and are receiving a push notification. Trying to open the video call answer button the moment the call arrives, without clicking the notification, just like in Whatsapp, Google Duo... (in Android phones)
We tried to have a Service running in the background with a socket open in it. The socket would listen to incoming calls and open the VideoCallActivity when an incoming call event is emitted to the socket.
This was our best bet but no success so far. How would you achieve this functionality?
So we had figured out this solution (when a notification arrives, bring the app to foreground) and I'm posting it even though it's been a while:
The FCM notification (firebase cloud messaging notification) needs to only send "data" in the notification. So no Notification object in the JSON structure of the notification, only data. This way the notification is handled by your app's FirebaseMessagingService.java class. Please read the below in detail to understand how 2 FCM notification types are handled. https://firebase.google.com/docs/cloud-messaging/android/receive https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages
In the FirebaseMessagingService.java class, launch a VideoCall activity with an Intent. Don't forget to add this service to the Manifest.xml
In the VideoCall activity, make sure you have the below code in the beginning of onCreate() :
Add the VideoCallActivity to the Manifest.xml with the appropriate intent-filter:
<!-- Video Call --> <activity android:name=".ui.activities.video_call.VideoCallActivity" android:launchMode="singleTop" android:screenOrientation="portrait" android:theme="@style/AppTheme.NoActionBar"> <intent-filter> <!-- Note: these actions are notification actions --> <action android:name="VIDEO_CALLING" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>
Optional: To make the phone ring and vibrate: