+ 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.

13th Dec 2020, 8:09 AM
Gabriel
5 Answers
+ 2
Gabriel , You are defining that function `hasRecordAudioPermission()` outside class. Move the function inside class and see if it works. *fingers crossed*
13th Dec 2020, 8:33 AM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 2
Gabriel , Great! I was writing code to show you but you already fixed it 😁😁
13th Dec 2020, 8:43 AM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 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.
13th Dec 2020, 8:15 AM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 1
🇮🇳Omkar🕉 found it! Thank you so much!
13th Dec 2020, 8:36 AM
Gabriel
13th Dec 2020, 8:20 AM
Gabriel