当应用程序处于关闭状态时,是否可以从底部显示通知



问题-所以事情是这样的,当应用程序处于关闭状态时,尝试从应用程序的底部显示通知,或者它可以是任何类似于具有非常高优先级但应该从底部显示的通知的东西,并且应该使用WorkManager来完成,使其每天在指定的时间出现

做了很多研究,正如你所看到的,没有找到任何相关的信息来解决我的小问题。

我试过-在工人类的doWork方法中显示一个snackBar

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"
}
}

此当前代码在屏幕顶部显示具有高优先级的通知

所以问题是-是否有任何方法可以显示任何类似于高优先级通知的内容,并在应用程序状态终止时从底部显示?

它应该类似于这个图片

这是的外观示例

我认为你需要的是android中的底部表单,它从底部出现。当应用程序被终止时,会调用onDestroy(){check comments},因此您可以在其中调用底部页。为了确保它不会被应用程序杀死:https://stackoverflow.com/a/52258125/15552614看看这个。

最新更新