rns-nativecall 0.7.3 → 0.7.4
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,7 +6,6 @@ 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
|
|
10
9
|
import android.media.Ringtone
|
|
11
10
|
import android.media.RingtoneManager
|
|
12
11
|
import android.graphics.Color
|
|
@@ -112,57 +111,86 @@ object NativeCallManager {
|
|
|
112
111
|
// }
|
|
113
112
|
// }
|
|
114
113
|
|
|
114
|
+
fun handleIncomingPush(context: Context, data: Map<String, String>) {
|
|
115
|
+
val uuid = data["callUuid"] ?: return
|
|
116
|
+
stopRingtone()
|
|
115
117
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
val name = data["name"] ?: "Incoming Call"
|
|
119
|
+
val callType = data["callType"] ?: "audio"
|
|
120
|
+
val notificationId = uuid.hashCode()
|
|
119
121
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
122
|
+
val pendingFlags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
123
|
+
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
|
|
124
|
+
} else {
|
|
125
|
+
PendingIntent.FLAG_UPDATE_CURRENT
|
|
126
|
+
}
|
|
123
127
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
// 2. Intents (Keep your existing intent logic)
|
|
131
|
-
val intentToActivity = Intent(context, AcceptCallActivity::class.java).apply {
|
|
132
|
-
this.action = "ACTION_ANSWER_$uuid"
|
|
133
|
-
data.forEach { (key, value) -> this.putExtra(key, value) }
|
|
134
|
-
this.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
|
135
|
-
}
|
|
128
|
+
// 1. Setup the Intents
|
|
129
|
+
val intentToActivity = Intent(context, AcceptCallActivity::class.java).apply {
|
|
130
|
+
this.action = "ACTION_ANSWER_$uuid"
|
|
131
|
+
data.forEach { (key, value) -> this.putExtra(key, value) }
|
|
132
|
+
this.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
|
133
|
+
}
|
|
136
134
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
|
|
141
|
-
else PendingIntent.FLAG_UPDATE_CURRENT
|
|
142
|
-
)
|
|
135
|
+
val fullScreenPendingIntent = PendingIntent.getActivity(
|
|
136
|
+
context, notificationId, intentToActivity, pendingFlags
|
|
137
|
+
)
|
|
143
138
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
.
|
|
152
|
-
|
|
153
|
-
.setFullScreenIntent(fullScreenPendingIntent, true)
|
|
154
|
-
.setStyle(
|
|
155
|
-
NotificationCompat.CallStyle.forIncomingCall(
|
|
156
|
-
caller,
|
|
157
|
-
rejectPendingIntent, // Use your existing rejectIntent
|
|
158
|
-
fullScreenPendingIntent
|
|
159
|
-
)
|
|
139
|
+
val rejectIntent = Intent(context, CallActionReceiver::class.java).apply {
|
|
140
|
+
this.action = "ACTION_REJECT_$uuid"
|
|
141
|
+
this.putExtra("EXTRA_CALL_UUID", uuid)
|
|
142
|
+
data.forEach { (key, value) -> this.putExtra(key, value) }
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Fix: Define the missing rejectPendingIntent
|
|
146
|
+
val rejectPendingIntent = PendingIntent.getBroadcast(
|
|
147
|
+
context, notificationId, rejectIntent, pendingFlags
|
|
160
148
|
)
|
|
161
149
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
150
|
+
// 2. Create the Person object for CallStyle
|
|
151
|
+
val caller = Person.Builder()
|
|
152
|
+
.setName(name)
|
|
153
|
+
.setImportant(true)
|
|
154
|
+
.build()
|
|
155
|
+
|
|
156
|
+
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
|
157
|
+
|
|
158
|
+
// 3. Setup Channel
|
|
159
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
160
|
+
val channel = NotificationChannel(
|
|
161
|
+
channelId,
|
|
162
|
+
"Incoming Calls",
|
|
163
|
+
NotificationManager.IMPORTANCE_HIGH
|
|
164
|
+
).apply {
|
|
165
|
+
enableVibration(true)
|
|
166
|
+
vibrationPattern = longArrayOf(0, 500, 500, 500)
|
|
167
|
+
lightColor = Color.GREEN
|
|
168
|
+
setBypassDnd(true)
|
|
169
|
+
setSound(null, null)
|
|
170
|
+
}
|
|
171
|
+
notificationManager.createNotificationChannel(channel)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// 4. Build with CallStyle
|
|
175
|
+
val builder = NotificationCompat.Builder(context, channelId)
|
|
176
|
+
.setSmallIcon(context.applicationInfo.icon)
|
|
177
|
+
.setPriority(NotificationCompat.PRIORITY_MAX)
|
|
178
|
+
.setCategory(NotificationCompat.CATEGORY_CALL)
|
|
179
|
+
.setOngoing(true)
|
|
180
|
+
.setAutoCancel(false)
|
|
181
|
+
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
|
182
|
+
.setFullScreenIntent(fullScreenPendingIntent, true)
|
|
183
|
+
.setStyle(
|
|
184
|
+
NotificationCompat.CallStyle.forIncomingCall(
|
|
185
|
+
caller,
|
|
186
|
+
rejectPendingIntent,
|
|
187
|
+
fullScreenPendingIntent
|
|
188
|
+
)
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
notificationManager.notify(notificationId, builder.build())
|
|
192
|
+
|
|
193
|
+
// 5. Start Ringtone
|
|
166
194
|
try {
|
|
167
195
|
val ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE)
|
|
168
196
|
ringtone = RingtoneManager.getRingtone(context, ringtoneUri)
|
|
@@ -173,7 +201,8 @@ fun handleIncomingPush(context: Context, data: Map<String, String>) {
|
|
|
173
201
|
} catch (e: Exception) {
|
|
174
202
|
e.printStackTrace()
|
|
175
203
|
}
|
|
176
|
-
}
|
|
204
|
+
}
|
|
205
|
+
|
|
177
206
|
|
|
178
207
|
fun stopRingtone() {
|
|
179
208
|
try {
|
|
@@ -222,7 +251,6 @@ fun aborting(context: Context, uuid: String, name: String, callType: String) {
|
|
|
222
251
|
notificationManager.notify(notificationId, builder.build())
|
|
223
252
|
}
|
|
224
253
|
|
|
225
|
-
|
|
226
254
|
fun dismissIncomingCall(context: Context, uuid: String?) {
|
|
227
255
|
stopRingtone()
|
|
228
256
|
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|