+ 1
Android Studio private function Error ActivityCompat
Dear SoloLearn Community I develope an android app with a request record audio permission function which should be activated on an button click. Yet, I simply made a function which checks, if the user has the permission. private fun hasRecordAudioPermission() = ActivityCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) Here is the error I got: 'this' is not defined in this context. I don't know what to do now. Please, can you help me? Thank you.
5 Answers
+ 2
Gabriel ,
You are defining that function `hasRecordAudioPermission()` outside class.
Move the function inside class and see if it works. *fingers crossed*
+ 2
Gabriel ,
Great! I was writing code to show you but you already fixed it 😁😁
+ 1
Gabriel ,
not an expert in Android but maybe I can help 😬
Can you please provide complete code from that file? Post it in playground and share a link here. With given code I can't see what `this` might be refering to in that context.
+ 1
🇮🇳Omkar🕉 found it! Thank you so much!
0
🇮🇳Omkar🕉 Yes, here it is:
https://code.sololearn.com/c28IfqnME486/?ref=app