Skip to content

Commit

Permalink
Feat/engdesk 37034 (#392)
Browse files Browse the repository at this point in the history
* Init Handle Missed Call Push Notification for when socket is not connected

* Code CleanUp

* Code CleanUp
  • Loading branch information
isaacakakpo1 authored Jan 17, 2025
1 parent 6075a6a commit cbe63dc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ class NotificationsService : Service() {

val builder = NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_stat_contact_phone)
.setContentTitle("Incoming Call")
.setContentText("Incoming call from: ")
.setContentTitle("Incoming Call : ${txPushMetaData.callerName}")
.setContentText("Incoming call from: ${txPushMetaData.callerNumber} ")
.setPriority(NotificationCompat.PRIORITY_MAX)
.setContentIntent(pendingIntent)
.setSound(customSoundUri)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package com.telnyx.webrtc.sdk.utility

import android.content.Intent
import android.os.Build
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import com.google.gson.Gson
Expand All @@ -29,10 +30,22 @@ class MyFirebaseMessagingService : FirebaseMessagingService() {
val params = remoteMessage.data
val objects = JSONObject(params as Map<*, *>)
val metadata = objects.getString("metadata")
val isMissedCall: Boolean = objects.getString("message").equals(Missed_Call)

if(isMissedCall){
Timber.d("Missed Call")
val serviceIntent = Intent(this, NotificationsService::class.java).apply {
putExtra("action", NotificationsService.STOP_ACTION)
}
serviceIntent.setAction(NotificationsService.STOP_ACTION)
startMessagingService(serviceIntent)
return
}

val serviceIntent = Intent(this, NotificationsService::class.java).apply {
putExtra("metadata", metadata)
}
startForegroundService(serviceIntent)
startMessagingService(serviceIntent)
}


Expand All @@ -56,12 +69,12 @@ class MyFirebaseMessagingService : FirebaseMessagingService() {
Timber.d("sendRegistrationTokenToServer($token)")
}

/**
* Create and show a simple notification containing the received FCM message.
*
* @param messageBody FCM message body received.
*/
private fun sendNotification(messageBody: String) {
private fun startMessagingService(serviceIntent: Intent) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(serviceIntent)
} else {
startService(serviceIntent)
}
}

companion object {
Expand All @@ -71,6 +84,7 @@ class MyFirebaseMessagingService : FirebaseMessagingService() {
const val REJECT_REQUEST_CODE = 1

const val TX_PUSH_METADATA = "tx_push_metadata"
const val Missed_Call = "Missed call!"

const val EXT_KEY_DO_ACTION = "ext_key_do_action"
const val EXT_CALL_ID = "ext_call_id"
Expand Down
21 changes: 20 additions & 1 deletion docs-markdown/push-notification/app-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,23 @@ You are now ready to receive push notifications via Firebase Messaging Service.
android:name=".ForegroundService"
android:foregroundServiceType="phoneCall"
android:exported="true" />
```
```
### Handling Missed Call Notifications
The backend sends a missed call notification when a call is ended while the socket is not yet connected. It comes with the `Missed call!` message. In order to handle missed call notifications, you can use the following code snippet in the FirebaseMessagingService class:
``` kotlin
const val Missed_Call = "Missed call!"
val params = remoteMessage.data
val objects = JSONObject(params as Map<*, *>)
val metadata = objects.getString("metadata")
val isMissedCall: Boolean = objects.getString("message").equals(Missed_Call) //

if(isMissedCall){
Timber.d("Missed Call")
val serviceIntent = Intent(this, NotificationsService::class.java).apply {
putExtra("action", NotificationsService.STOP_ACTION)
}
serviceIntent.setAction(NotificationsService.STOP_ACTION)
startMessagingService(serviceIntent)
return
}
```

0 comments on commit cbe63dc

Please sign in to comment.