Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save LloydBlv/2707d704bb26112522fc0bfbc96cfd9c to your computer and use it in GitHub Desktop.
Save LloydBlv/2707d704bb26112522fc0bfbc96cfd9c to your computer and use it in GitHub Desktop.
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