i have a problem with chronometer in Notification. I want to get current tick if notification clicked and parsing value to MainActivity using Intent. i have no idea about this case, i was try and result is always 0.
here my notification code with RemoteView
fun showNotification(context: Context, value: Long, state: Int) {
val isPaused = state == Constant.MusicState.PAUSED
val intentTimer = Intent(context, MainActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
val bundle = Bundle()
bundle.putLong(Constant.Key.CURRENT_TIME, value)
val pendingIntentButtonPause = PendingIntent.getActivity(context, 100, intentTimer, PendingIntent.FLAG_UPDATE_CURRENT, bundle)
val remoteViews = RemoteViews(context.packageName, R.layout.item_notification)
remoteViews.setChronometer(R.id.chronometer, value, null, !isPaused)
remoteViews.setOnClickPendingIntent(R.id.buttonPause, pendingIntentButtonPause)
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val builder = NotificationCompat.Builder(context, "199102")
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentText("Test")
.setAutoCancel(false)
.setOngoing(true)
.setOnlyAlertOnce(true)
.setUsesChronometer(true)
.setContentIntent(PendingIntent.getActivity(context, 10, intentTimer, PendingIntent.FLAG_UPDATE_CURRENT))
remoteViews
builder.setCustomContentView(remoteViews)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
checkNotificationChannel(context, "199102")
}
notificationManager.notify(199102, builder.build())
}
And this when i call function showNotification()
this.binding.apply {
[email protected] = Constant.MusicState.IDLE
this.chronometer.setOnChronometerTickListener {
try {
if (it.text == "00.10" || it.text == "00:10") {
Chronotification.showNotification(this@MainActivity, it.base, [email protected])
[email protected] = Constant.MusicState.IDLE
[email protected] = "Start"
it.text = "00.00"
it.stop()
}
}catch (e : Exception) {
e.printStackTrace()
}
}
GeneralHelper.makeClickable(this@MainActivity, this.buttonStart)
}
Thanks, any help or suggestion will be appreciate.