Created
May 13, 2025 09:03
-
-
Save LloydBlv/2707d704bb26112522fc0bfbc96cfd9c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FakeNotificationFactoryThatShowsRealNotif( | |
private val context: Context | |
) : NotificationFactory { | |
init { | |
createNotificationChannel() | |
} | |
override fun createNotification(context: Context, message: PushMessage): Notification { | |
return NotificationCompat.Builder(context, TEST_CHANNEL_ID) | |
.setContentTitle(message.title ?: "Test Title") | |
.setContentText(message.body ?: "Test Body") | |
.setSmallIcon(android.R.drawable.ic_dialog_info) | |
.setPriority(NotificationCompat.PRIORITY_HIGH) | |
.build().also { | |
NotificationManagerCompat.from(context).notify(TEST_NOTIFICATION_ID, it) | |
} | |
} | |
private fun createNotificationChannel() { | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |
val name = "Test Channel" | |
val importance = NotificationManager.IMPORTANCE_HIGH | |
val channel = NotificationChannel(TEST_CHANNEL_ID, name, importance) | |
NotificationManagerCompat.from(context).createNotificationChannel(channel) | |
} | |
} | |
companion object { | |
private const val TEST_CHANNEL_ID = "test_channel" | |
private const val TEST_NOTIFICATION_ID = 42 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment