I will most likely encounter this problem for other methods/classes as well so it’s more a general question not specific to MediaRecorder, it just serves as an example here.
I use android.media.MediaRecorder
. Instantiating it with MediaRecorder()
gives me the deprecation warning: Use MediaRecorder(android.context.Context)
instead.
Since MediaRecorder(android.context.Context)
was added in API 31 and my application supports API < 31, i tried to extract the instantiation like this:
private fun createMediaRecorder(context: Context) : MediaRecorder {
return if (Build.VERSION.SDK_INT < 31) {
MediaRecorder()
} else {
MediaRecorder(context)
}
}
However, the MediaRecorder()
line still gives me the deprecation warning. Can I properly resolve that warning without having to use a suppress annotation ? To me it feels like the deprecation tag on the constructor needs to be more specific here and say it’s only deprecated on API >= 31 since there is no other way on API < 31 to use that constructor or am I missing something here ?