Skip to content

Commit 9bb6713

Browse files
committed
Fix intents being overwritten
1 parent 3d6b0ff commit 9bb6713

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

app/src/main/kotlin/org/fossify/phone/receivers/MissedCallReceiver.kt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import android.graphics.drawable.Icon
1111
import android.net.Uri
1212
import android.os.Build
1313
import android.telecom.TelecomManager
14-
import android.util.Log
1514
import androidx.annotation.RequiresApi
1615
import androidx.core.app.NotificationCompat
1716
import org.fossify.commons.extensions.getLaunchIntent
@@ -35,10 +34,10 @@ class MissedCallReceiver : BroadcastReceiver() {
3534

3635
when (intent.action) {
3736
TelecomManager.ACTION_SHOW_MISSED_CALLS_NOTIFICATION -> {
38-
notificationId = Random.nextInt()
39-
phoneNumber = extras.getString(TelecomManager.EXTRA_NOTIFICATION_PHONE_NUMBER)
4037
val notificationCount = extras.getInt(TelecomManager.EXTRA_NOTIFICATION_COUNT)
4138
if (notificationCount != 0) {
39+
notificationId = Random.nextInt()
40+
phoneNumber = extras.getString(TelecomManager.EXTRA_NOTIFICATION_PHONE_NUMBER)
4241
createNotificationChannel(context)
4342
notificationManager.notify(MISSED_CALLS.hashCode(), getNotificationGroup(context))
4443
notificationManager.notify(notificationId, buildNotification(context, notificationId, phoneNumber ?: return))
@@ -67,7 +66,6 @@ class MissedCallReceiver : BroadcastReceiver() {
6766

6867
else -> null
6968
}?.let {
70-
Log.d("MISSEDCALL", it.toString())
7169
context.startActivity(it)
7270
context.notificationManager.cancel(notificationId)
7371
}
@@ -78,14 +76,14 @@ class MissedCallReceiver : BroadcastReceiver() {
7876
val channel = NotificationChannel(
7977
"missed_call_channel",
8078
context.getString(R.string.missed_call_channel),
81-
NotificationManager.IMPORTANCE_LOW
79+
NotificationManager.IMPORTANCE_DEFAULT
8280
)
8381
notificationManager.createNotificationChannel(channel)
8482
}
8583

8684
private fun launchIntent(context: Context): PendingIntent {
8785
return PendingIntent.getActivity(
88-
context, 0, context.getLaunchIntent(), PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
86+
context, 0, context.getLaunchIntent(), PendingIntent.FLAG_IMMUTABLE
8987
)
9088
}
9189

@@ -110,7 +108,7 @@ class MissedCallReceiver : BroadcastReceiver() {
110108
putExtra("phoneNumber", phoneNumber)
111109
}
112110
val callBackIntent = PendingIntent.getBroadcast(
113-
context, 0, callBack, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
111+
context, notificationId, callBack, PendingIntent.FLAG_IMMUTABLE
114112
)
115113

116114
val smsIntent = Intent(context, MissedCallReceiver::class.java).apply {
@@ -119,7 +117,7 @@ class MissedCallReceiver : BroadcastReceiver() {
119117
putExtra("phoneNumber", phoneNumber)
120118
}
121119
val messageIntent = PendingIntent.getBroadcast(
122-
context, 0, smsIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
120+
context, notificationId, smsIntent, PendingIntent.FLAG_IMMUTABLE
123121
)
124122

125123
val cancel = Intent(context, MissedCallReceiver::class.java).apply {
@@ -128,7 +126,7 @@ class MissedCallReceiver : BroadcastReceiver() {
128126
putExtra("phoneNumber", phoneNumber)
129127
}
130128
val cancelIntent = PendingIntent.getActivity(
131-
context, 0, cancel, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
129+
context, notificationId, cancel, PendingIntent.FLAG_IMMUTABLE
132130
)
133131

134132
return NotificationCompat.Builder(context, "missed_call_channel")

0 commit comments

Comments
 (0)