Reputation: 77
how to solve this? any ideia? thanks for any help
private var notificationManager: NotificationManager? = null
......
problem Classifier 'NotificationManager' does not have a companion object, and thus must be initialized here
code line ->
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
code
override fun onChildAdded(ds: DataSnapshot, prevChildKey: String?) {
Log.i(TAG, " child added")
if(markers.size == 0) {
pushIssueMarker(ds)
}
builder.setSmallIcon(R.mipmap.ic_launcher);
builder.setContentTitle("Firebase Push Notification");
builder.setContentText("Hello this is a test Firebase notification, a new database child has been added");
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager?.notify(1, builder.build());
}
Upvotes: 1
Views: 847
Reputation: 116
you don't need to break into two lines, you can eaisly initialize it as
val mNotificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
Upvotes: 0
Reputation: 2160
You are coding in Kotlin. So its object creation is different than JAVA.
Change your below line
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
to this line
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
Upvotes: 1