error: getSystemServise unresolved reference - kotlin android studio
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?
I assume your code is inside a Fragment
and that's why you reference this.activity
in it multiple times. As getSystemService()
is a method on the Context
class, you need a Context
instance to call it on. You can get one by either using getContext()
or alternatively, the getActivity()
which you've already been using (since an Activity
is also a Context
).
With Kotlin's property access syntax, this would look something like:
// either of these
this.activity.getSystemService(...)
this.context.getSystemService(...)
Or even just:
// either of these
activity.getSystemService(...)
context.getSystemService(...)