Problem - So here is the thing, Trying to get notification appear from the bottom side of the app while the app is in killed state or it can be anything that can act like a notification that has very high priority but should appear from the bottom side, and it should be done with WorkManager, that makes it appear every day at specified time
Did a lot research and as you can see could not find any relevant information that solves my little problem.
I have tried - To show a snackBar in doWork method of the Worker Class
class NotifyWork(context: Context, params: WorkerParameters) : Worker(context, params) {
override fun doWork(): Result {
// val mySnackbar = Snackbar()
val id = inputData.getLong(NOTIFICATION_ID, 0).toInt()
sendNotification(id)
return success()
}
private fun sendNotification(id: Int) {
val intent = Intent(applicationContext, MainActivity::class.java)
intent.flags = FLAG_ACTIVITY_NEW_TASK or FLAG_ACTIVITY_CLEAR_TASK
intent.putExtra(NOTIFICATION_ID, id)
val notificationManager =
applicationContext.getSystemService(NOTIFICATION_SERVICE) as NotificationManager
val notificationLayoutExpanded =
RemoteViews(applicationContext.packageName, R.layout.layout_notification)
val bitmap = applicationContext.vectorToBitmap(R.mipmap.ic_launcher)
val pendingIntent = getActivity(applicationContext, 0, intent, 0)
val notification = NotificationCompat.Builder(applicationContext, NOTIFICATION_CHANNEL)
.setLargeIcon(bitmap)
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setAutoCancel(true)
.setPriority(PRIORITY_MAX)
.setCustomContentView(notificationLayoutExpanded)
.setOngoing(true)
.setFullScreenIntent(pendingIntent, true)
.setContentIntent(pendingIntent)
notification.priority = PRIORITY_MAX
if (SDK_INT >= O) {
notification.setChannelId(NOTIFICATION_CHANNEL)
val ringtoneManager = getDefaultUri(TYPE_NOTIFICATION)
val audioAttributes = AudioAttributes.Builder().setUsage(USAGE_NOTIFICATION_RINGTONE)
.setContentType(CONTENT_TYPE_SONIFICATION).build()
val channel =
NotificationChannel(NOTIFICATION_CHANNEL, NOTIFICATION_NAME, IMPORTANCE_HIGH)
channel.enableLights(true)
channel.lightColor = RED
channel.enableVibration(true)
channel.vibrationPattern = longArrayOf(100, 200, 300, 400, 500, 400, 300, 200, 400)
channel.setSound(ringtoneManager, audioAttributes)
notificationManager.createNotificationChannel(channel)
}
notificationManager.notify(id, notification.build())
}
companion object {
const val NOTIFICATION_ID = "appName_notification_id"
const val NOTIFICATION_NAME = "appName"
const val NOTIFICATION_CHANNEL = "appName_channel_01"
const val NOTIFICATION_WORK = "appName_notification_work"
}
}
This current code shows notification with high priority on top of the screen
So the question is - IS there any way to show anything that acts like a notification with high priority and appears from bottom when app's state is killed ?
it should be similar to this picture