Hello,
I was following the book with code and after my result receiver implementation shown in Listing 28.12
class NotificationReceiver: BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
Log.i(TAG, "received result: $resultCode")
if (resultCode != Activity.RESULT_OK) {
//A foreground activity canceled the broadcast
return
}
val requestCode = intent.getIntExtra(PollWorker.REQUEST_CODE, 0)
val notification: Notification =
intent.getParcelableExtra(PollWorker.NOTIFICATION)
val notificationManager = NotificationManagerCompat.from(context)
notificationManager.notify(requestCode, notification)
}
companion object {
private const val TAG = "NotificationReceiver"
}
}
I am getting an error:
Type mismatch: inferred type is Notification? but Notification was expected
It is linked to this line:
val notification: Notification =
intent.getParcelableExtra(PollWorker.NOTIFICATION)
Should I use the double exclamation mark there?
Note:
In PollWorker.kt
const val NOTIFICATION is the same as shown in listing 28.11:
const val NOTIFICATION = "NOTIFICATION"