Skip to content

Commit

Permalink
Merge pull request #506 from code-payments/chore/open-app-from-notifi…
Browse files Browse the repository at this point in the history
…cation

chore: open app from push notification
  • Loading branch information
bmc08gt authored Aug 13, 2024
2 parents cfec920 + 567c9a3 commit 553b69b
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package com.getcode.notifications
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.media.RingtoneManager
import android.os.Build
import androidx.core.app.NotificationCompat
Expand All @@ -26,6 +28,7 @@ import com.getcode.util.resources.ResourceHelper
import com.getcode.util.resources.ResourceType
import com.getcode.utils.ErrorUtils
import com.getcode.utils.installationId
import com.getcode.view.MainActivity
import com.google.firebase.Firebase
import com.google.firebase.installations.installations
import com.google.firebase.messaging.FirebaseMessagingService
Expand Down Expand Up @@ -183,6 +186,7 @@ class CodePushMessagingService : FirebaseMessagingService(),
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setSmallIcon(R.drawable.ic_code_logo_outline)
.setAutoCancel(true)
.setContentIntent(buildContentIntent(type))

notificationManager.notify(title.hashCode(), notificationBuilder.build())
}
Expand All @@ -207,6 +211,19 @@ class CodePushMessagingService : FirebaseMessagingService(),
}
}

private fun Context.buildContentIntent(type: NotificationType): PendingIntent {
val launchIntent = Intent(this, MainActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
}

return PendingIntent.getActivity(
this,
type.ordinal,
launchIntent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
}


private fun NotificationManager.getActiveNotification(notificationId: Int): Notification? {
val barNotifications = getActiveNotifications()
Expand Down

0 comments on commit 553b69b

Please sign in to comment.