@qusaieilouti99/call-manager 0.1.10 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/android/src/main/java/com/qusaieilouti99/callmanager/CallNotificationActionReceiver.kt
CHANGED
|
@@ -3,19 +3,26 @@ package com.qusaieilouti99.callmanager
|
|
|
3
3
|
import android.content.BroadcastReceiver
|
|
4
4
|
import android.content.Context
|
|
5
5
|
import android.content.Intent
|
|
6
|
+
import android.util.Log
|
|
6
7
|
|
|
7
8
|
class CallNotificationActionReceiver : BroadcastReceiver() {
|
|
8
9
|
override fun onReceive(context: Context, intent: Intent) {
|
|
9
10
|
val callId = intent.getStringExtra("callId") ?: return
|
|
10
|
-
val
|
|
11
|
-
?.reactNativeHost
|
|
12
|
-
?.reactInstanceManager
|
|
13
|
-
?.currentReactContext
|
|
14
|
-
?.getNativeModule(CallManagerModule::class.java)
|
|
11
|
+
val action = intent.action
|
|
15
12
|
|
|
16
|
-
|
|
13
|
+
val app = context.applicationContext as? com.facebook.react.ReactApplication
|
|
14
|
+
val reactInstanceManager = app?.reactNativeHost?.reactInstanceManager
|
|
15
|
+
val reactContext = reactInstanceManager?.currentReactContext
|
|
16
|
+
val module = reactContext?.getNativeModule(CallManagerModule::class.java)
|
|
17
|
+
|
|
18
|
+
when (action) {
|
|
17
19
|
"com.qusaieilouti99.callmanager.ANSWER_CALL" -> {
|
|
18
|
-
module
|
|
20
|
+
if (module != null) {
|
|
21
|
+
module.answerCall(callId)
|
|
22
|
+
} else {
|
|
23
|
+
// ReactContext not ready, bring app to foreground
|
|
24
|
+
bringAppToForeground(context)
|
|
25
|
+
}
|
|
19
26
|
}
|
|
20
27
|
"com.qusaieilouti99.callmanager.DECLINE_CALL" -> {
|
|
21
28
|
module?.endCall(callId)
|
|
@@ -24,4 +31,13 @@ class CallNotificationActionReceiver : BroadcastReceiver() {
|
|
|
24
31
|
// Cancel notification and stop ringtone
|
|
25
32
|
CallNotificationHelper(context).cancelIncomingCallNotification()
|
|
26
33
|
}
|
|
34
|
+
|
|
35
|
+
private fun bringAppToForeground(context: Context) {
|
|
36
|
+
val packageName = context.packageName
|
|
37
|
+
val launchIntent = context.packageManager.getLaunchIntentForPackage(packageName)
|
|
38
|
+
launchIntent?.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP)
|
|
39
|
+
launchIntent?.putExtra("incomingCall", true)
|
|
40
|
+
context.startActivity(launchIntent)
|
|
41
|
+
Log.d("CallNotificationActionReceiver", "Bringing app to foreground for incoming call")
|
|
42
|
+
}
|
|
27
43
|
}
|
|
@@ -60,6 +60,7 @@ class CallNotificationHelper(private val context: Context) {
|
|
|
60
60
|
.build()
|
|
61
61
|
|
|
62
62
|
Notification.Builder(context, CHANNEL_ID)
|
|
63
|
+
.setSmallIcon(android.R.drawable.sym_call_incoming) // <-- REQUIRED!
|
|
63
64
|
.setStyle(
|
|
64
65
|
Notification.CallStyle.forIncomingCall(
|
|
65
66
|
person,
|
|
@@ -67,15 +68,15 @@ class CallNotificationHelper(private val context: Context) {
|
|
|
67
68
|
declinePendingIntent
|
|
68
69
|
)
|
|
69
70
|
)
|
|
70
|
-
.setFullScreenIntent(fullScreenPendingIntent, true)
|
|
71
|
+
.setFullScreenIntent(fullScreenPendingIntent, true)
|
|
71
72
|
.setOngoing(true)
|
|
72
73
|
.setAutoCancel(false)
|
|
73
74
|
.build()
|
|
74
75
|
} else {
|
|
75
76
|
Notification.Builder(context, CHANNEL_ID)
|
|
77
|
+
.setSmallIcon(android.R.drawable.sym_call_incoming) // <-- REQUIRED!
|
|
76
78
|
.setContentTitle("Incoming Call")
|
|
77
79
|
.setContentText(callerName)
|
|
78
|
-
.setSmallIcon(android.R.drawable.sym_call_incoming)
|
|
79
80
|
.setPriority(Notification.PRIORITY_HIGH)
|
|
80
81
|
.setCategory(Notification.CATEGORY_CALL)
|
|
81
82
|
.setFullScreenIntent(fullScreenPendingIntent, true)
|