rns-nativecall 0.7.6 → 0.7.7
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.
|
@@ -6,11 +6,13 @@ import android.app.PendingIntent
|
|
|
6
6
|
import android.content.Context
|
|
7
7
|
import android.content.Intent
|
|
8
8
|
import android.os.Build
|
|
9
|
+
import androidx.core.app.NotificationCompat
|
|
9
10
|
import android.media.Ringtone
|
|
10
11
|
import android.media.RingtoneManager
|
|
11
12
|
import android.graphics.Color
|
|
13
|
+
|
|
12
14
|
import androidx.core.app.Person
|
|
13
|
-
|
|
15
|
+
|
|
14
16
|
import android.app.KeyguardManager
|
|
15
17
|
|
|
16
18
|
object NativeCallManager {
|
|
@@ -18,37 +20,16 @@ object NativeCallManager {
|
|
|
18
20
|
private var ringtone: Ringtone? = null
|
|
19
21
|
const val channelId = "CALL_CHANNEL_ID"
|
|
20
22
|
|
|
21
|
-
// ✅ ADDED: stopRingtone definition
|
|
22
|
-
fun stopRingtone() {
|
|
23
|
-
try {
|
|
24
|
-
ringtone?.let { if (it.isPlaying) it.stop() }
|
|
25
|
-
ringtone = null
|
|
26
|
-
} catch (e: Exception) {
|
|
27
|
-
ringtone = null
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// ✅ ADDED: showMissedCallNotification definition
|
|
32
|
-
fun showMissedCallNotification(context: Context, data: Map<String, String>, uuid: String) {
|
|
33
|
-
val name = data["name"] ?: "Unknown Caller"
|
|
34
|
-
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
|
35
|
-
|
|
36
|
-
val builder = NotificationCompat.Builder(context, channelId)
|
|
37
|
-
.setSmallIcon(context.applicationInfo.icon)
|
|
38
|
-
.setContentTitle("Missed Call")
|
|
39
|
-
.setContentText("Incoming call from $name")
|
|
40
|
-
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
|
41
|
-
.setAutoCancel(true)
|
|
42
|
-
|
|
43
|
-
notificationManager.notify(uuid.hashCode(), builder.build())
|
|
44
|
-
}
|
|
45
|
-
|
|
46
23
|
fun handleIncomingPush(context: Context, data: Map<String, String>) {
|
|
47
24
|
val uuid = data["callUuid"] ?: return
|
|
48
25
|
stopRingtone()
|
|
49
26
|
|
|
50
27
|
val name = data["name"] ?: "Incoming Call"
|
|
51
28
|
val callType = data["callType"] ?: "audio"
|
|
29
|
+
val notificationId = uuid.hashCode()
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
52
33
|
|
|
53
34
|
// --- LOCK SCREEN GATEKEEPER ---
|
|
54
35
|
val keyguardManager = context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
|
|
@@ -59,14 +40,20 @@ object NativeCallManager {
|
|
|
59
40
|
return // 🛑 Flow stops here
|
|
60
41
|
}
|
|
61
42
|
|
|
62
|
-
|
|
43
|
+
|
|
44
|
+
|
|
63
45
|
val pendingFlags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
64
46
|
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
|
|
65
47
|
} else {
|
|
66
48
|
PendingIntent.FLAG_UPDATE_CURRENT
|
|
67
49
|
}
|
|
68
50
|
|
|
69
|
-
val noOpIntent = PendingIntent.getActivity(
|
|
51
|
+
val noOpIntent = PendingIntent.getActivity(
|
|
52
|
+
context,
|
|
53
|
+
notificationId + 1,
|
|
54
|
+
Intent(),
|
|
55
|
+
pendingFlags
|
|
56
|
+
)
|
|
70
57
|
|
|
71
58
|
val intentToActivity = Intent(context, AcceptCallActivity::class.java).apply {
|
|
72
59
|
this.action = "ACTION_SHOW_UI_$uuid"
|
|
@@ -74,7 +61,12 @@ object NativeCallManager {
|
|
|
74
61
|
this.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
|
75
62
|
}
|
|
76
63
|
|
|
77
|
-
val fullScreenPendingIntent = PendingIntent.getActivity(
|
|
64
|
+
val fullScreenPendingIntent = PendingIntent.getActivity(
|
|
65
|
+
context,
|
|
66
|
+
notificationId,
|
|
67
|
+
intentToActivity,
|
|
68
|
+
pendingFlags
|
|
69
|
+
)
|
|
78
70
|
|
|
79
71
|
val rejectIntent = Intent(context, CallActionReceiver::class.java).apply {
|
|
80
72
|
this.action = "ACTION_REJECT_$uuid"
|
|
@@ -82,12 +74,21 @@ object NativeCallManager {
|
|
|
82
74
|
data.forEach { (key, value) -> this.putExtra(key, value) }
|
|
83
75
|
}
|
|
84
76
|
|
|
85
|
-
val rejectPendingIntent = PendingIntent.getBroadcast(
|
|
77
|
+
val rejectPendingIntent = PendingIntent.getBroadcast(
|
|
78
|
+
context,
|
|
79
|
+
notificationId,
|
|
80
|
+
rejectIntent,
|
|
81
|
+
pendingFlags
|
|
82
|
+
)
|
|
86
83
|
|
|
87
84
|
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
|
88
85
|
|
|
89
86
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
90
|
-
val channel = NotificationChannel(
|
|
87
|
+
val channel = NotificationChannel(
|
|
88
|
+
channelId,
|
|
89
|
+
"Incoming Calls",
|
|
90
|
+
NotificationManager.IMPORTANCE_HIGH // NotificationManager.IMPORTANCE_HIGH
|
|
91
|
+
).apply {
|
|
91
92
|
enableVibration(true)
|
|
92
93
|
vibrationPattern = longArrayOf(0, 500, 500, 500)
|
|
93
94
|
lightColor = Color.GREEN
|
|
@@ -102,8 +103,8 @@ object NativeCallManager {
|
|
|
102
103
|
.setSmallIcon(context.applicationInfo.icon)
|
|
103
104
|
.setContentTitle("Incoming $callType call")
|
|
104
105
|
.setContentText(name)
|
|
105
|
-
.setPriority(NotificationCompat.PRIORITY_MAX)
|
|
106
|
-
.setCategory(NotificationCompat.CATEGORY_CALL)
|
|
106
|
+
.setPriority(NotificationCompat.PRIORITY_MAX) // PRIORITY_HIGH
|
|
107
|
+
.setCategory(NotificationCompat.CATEGORY_CALL) // CATEGORY_CALL
|
|
107
108
|
.setOngoing(true)
|
|
108
109
|
.setAutoCancel(false)
|
|
109
110
|
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
|
@@ -126,35 +127,53 @@ object NativeCallManager {
|
|
|
126
127
|
}
|
|
127
128
|
}
|
|
128
129
|
|
|
129
|
-
fun
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
.setPriority(NotificationCompat.PRIORITY_MAX)
|
|
137
|
-
.setCategory(NotificationCompat.CATEGORY_CALL)
|
|
138
|
-
.setOngoing(true)
|
|
139
|
-
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
|
140
|
-
.setProgress(0, 0, true)
|
|
141
|
-
notificationManager.notify(notificationId, builder.build())
|
|
130
|
+
fun stopRingtone() {
|
|
131
|
+
try {
|
|
132
|
+
ringtone?.let { if (it.isPlaying) it.stop() }
|
|
133
|
+
ringtone = null
|
|
134
|
+
} catch (e: Exception) {
|
|
135
|
+
ringtone = null
|
|
136
|
+
}
|
|
142
137
|
}
|
|
143
138
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
139
|
+
fun connecting(context: Context, uuid: String, name: String, callType: String) {
|
|
140
|
+
val notificationId = uuid.hashCode()
|
|
141
|
+
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
|
142
|
+
|
|
143
|
+
val builder = NotificationCompat.Builder(context, channelId)
|
|
144
|
+
.setSmallIcon(context.applicationInfo.icon)
|
|
145
|
+
.setContentTitle("Incoming $callType call")
|
|
146
|
+
.setContentText("Connecting…") // ✅ show connecting text
|
|
147
|
+
.setSubText("Connecting…") // status line
|
|
148
|
+
.setPriority(NotificationCompat.PRIORITY_MAX)
|
|
149
|
+
.setCategory(NotificationCompat.CATEGORY_CALL)
|
|
150
|
+
.setOngoing(true)
|
|
151
|
+
.setAutoCancel(false)
|
|
152
|
+
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
|
153
|
+
.setProgress(0, 0, true) // ✅ system activity indicator (indeterminate progress bar)
|
|
154
|
+
|
|
155
|
+
notificationManager.notify(notificationId, builder.build())
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
fun aborting(context: Context, uuid: String, name: String, callType: String) {
|
|
159
|
+
val notificationId = uuid.hashCode()
|
|
160
|
+
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
|
161
|
+
|
|
162
|
+
val builder = NotificationCompat.Builder(context, channelId)
|
|
163
|
+
.setSmallIcon(context.applicationInfo.icon)
|
|
164
|
+
.setContentTitle("Incoming $callType call")
|
|
165
|
+
.setContentText("Aborting…") // ✅ show aborting text
|
|
166
|
+
.setSubText("Aborting…") // status line
|
|
167
|
+
.setPriority(NotificationCompat.PRIORITY_MAX)
|
|
168
|
+
.setCategory(NotificationCompat.CATEGORY_CALL)
|
|
169
|
+
.setOngoing(true)
|
|
170
|
+
.setAutoCancel(false)
|
|
171
|
+
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
|
172
|
+
.setProgress(0, 0, true) // ✅ indeterminate progress indicator
|
|
173
|
+
|
|
174
|
+
notificationManager.notify(notificationId, builder.build())
|
|
175
|
+
}
|
|
176
|
+
|
|
158
177
|
|
|
159
178
|
fun dismissIncomingCall(context: Context, uuid: String?) {
|
|
160
179
|
stopRingtone()
|