contentResolver is Unresolved reference: contentResolver how do I rectify this?
class fragment_edcards_media_animimage : Fragment() {
// TODO: Rename and change types of parameters
private var param1: String? = null
private var param2: String? = null
lateinit var u : FragmentEdcardsMediaAnimimageBinding
// Animated Image
private val getContentCardAnimImage = registerForActivityResult(ActivityResultContracts.GetContent()) { uri: Uri ->
val contentResolver = contentResolver
val source = ImageDecoder.createSource( contentResolver, uri )
val drawable = ImageDecoder.decodeDrawable(source)
Log.d("EditCards",uri.toString())
//u.iViewAnimImage.setImageDrawable(drawable)
if (drawable is AnimatedImageDrawable){
drawable.start()
//drawable.repeatCount = 2
}
val file = File( uri?.path )
mydecklist[cCardPosition].c_animimageuri = mytools.getImageFromMediaStore(u.iViewAnimImage.context,file.name)
}
Attempt #1 activity.contentResovlver results in; Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type FragmentActivity?
Attempt #2 val contentResolver = activity?.contentResolver
val source = ImageDecoder.createSource( contentResolver, uri ) Type mismatch: inferred type is ContentResolver? but ContentResolver was expected
I've bolded where it thinks the error is in the line ImageDecoder.
Attempt #3 val contentResolver = getActivity().contentResolver() Expression 'contentResolver' of type 'ContentResolver!' cannot be invoked as a function. The function 'invoke()' is not found
And
Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type FragmentActivity?
!!
where not null are needed – Anshulval contentResolver = requireActivity().contentResolver
– CommonsWare