Junior — Middle
Could you explain what notifications in the app are, sent directly to the user's system?
sobes.tech AI
Answer from AI
In-app notifications are messages that the app sends directly to the device's notification system area. They appear outside the app itself, for example, in the Android notification shade, and inform the user about important events, new messages, updates, etc.
These notifications can be local (created by the app on the device) or push notifications (sent from the server via services like Firebase Cloud Messaging). They help maintain communication with the user even when the app is not active.
Example of creating a simple local notification on Android:
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val channelId = "channel_id"
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(channelId, "Channel name", NotificationManager.IMPORTANCE_DEFAULT)
notificationManager.createNotificationChannel(channel)
}
val notification = NotificationCompat.Builder(this, channelId)
.setContentTitle("New message")
.setContentText("You have a new notification")
.setSmallIcon(R.drawable.ic_notification)
.build()
notificationManager.notify(1, notification)