Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: getSystemServise unresolved reference - kotlin android studio

hay im new in kotlin and i try to push notification in my app. Unfortunately I'm having this error: "getSystemServise unresolved reference" this is my code:

        val intent = Intent()
        val pendingIntent = PendingIntent.getActivity(this.activity,0,intent,0)
        val notification = Notification.Builder(this.activity)
                .setContentTitle("time is:")
                .setContentText("text")
                .setSmallIcon(R.drawable.notification_icon_background)
                .setContentIntent(pendingIntent)

        val nm:NotificationManager = getSystemService(Context.NOTIFICATION_SERVICE);
        nm.notify(0,notification.build())

thanks for helpers

like image 564
Roy Oknin Avatar asked Mar 11 '18 14:03

Roy Oknin


People also ask

How do I fix unresolved reference Kotlin?

Please make sure that you add the id 'kotlin-android-extensions' line on the build. gradle file that's inside your app module. Once you sync the Gradle build, the error should disappear.


1 Answers

I was also facing the same issue.
I got the partial solution with the previous answers, but there is one more thing that you have to mention, i.e. that the variable is nullable or not and put the operators accordingly:

val downloadManager = context?.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager?
like image 91
Aagam Shah Avatar answered Oct 12 '22 09:10

Aagam Shah