【发布时间】:2021-08-15 06:39:54
【问题描述】:
如果用户单击通知,我会尝试打开片段而不是活动
这里是通知功能:
private fun sendNotification(nextPray: Pray) {
log("Send Notification")
//small view
val collapsedView = RemoteViews(
packageName,
R.layout.notification_collapsed
)
//big view
val expandedView = RemoteViews(
packageName,
R.layout.notification_expanded
)
val snoozeIntent = Intent(this, StopAlarm::class.java)
val snoozePendingIntent = PendingIntent.getBroadcast(this, 0, snoozeIntent, 0)
val notificationIntent = Intent(this, FullAzan::class.java)
val pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0)
val mBuilder: NotificationCompat.Builder = NotificationCompat.Builder(this, CHANNEL_ID2)
.setSmallIcon(R.drawable.qalby_ic)
.setCustomContentView(collapsedView)
//.setCustomBigContentView(expandedView)
.setContentTitle("It's Time for ${nextPray.name}")
.setContentText("Let's Pray")
.setContentIntent(pendingIntent)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.addAction(
R.drawable.ic_stop,
getString(R.string.text_stop),
snoozePendingIntent
)
.setChannelId(CHANNEL_ID2)
.setAutoCancel(true)
val notification = mBuilder.build()
notificationManager = NotificationManagerCompat.from(this)
notificationManager.notify(100, notification)
//startForeground(100, notification)
log("vibrating")
vibrate()
log("Azan Audio Started")
MediaPlayerManager.getInstance(applicationContext).azan(nextPray)
}
在这些行中:
val notificationIntent = Intent(this, FullAzan::class.java)
val pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0)
我初始化了它
并在这一行中调用它:
.setContentIntent(pendingIntent)
我想用片段而不是当前的活动替换“Intent(this, FullAzan::class.java)”,这样做的正确方法是什么?
【问题讨论】:
-
您需要自己处理这个问题,例如,在
notificationIntent上添加一个额外的内容,您可以在FullAzan中阅读,然后决定显示哪个Fragment。 -
你能说得更具体些吗,因为我是 kotlin 新手
标签: java android kotlin notifications fragment