So watch faces are Android Wear apps that don't have any activities but only a service. It's visible and interactive, but a service. And if the app wants to access anything like location or settings, it needs to request the corresponding permissions in code. Adding it to the manifest file is not effective, despite all tutorials saying so. Maybe they're outdated faster than things change on Android.
There is the ContextCompat.checkSelfPermission
function to check whether the app has a certain permission. This can be called before I do anything. But if it says I don't have that permission, it must be requested.
There is the ActivityCompat.requestPermissions
function to request a permission from the user through a dialog view. Unfortunately this requires an activity which a watch face doesn't have.
I've seen another question about this issue but it has no useful answers. The answers include external libraries (I've tried the two and none of them works), a code sample in Java that also fails because it extends from AppCompatActivity
that doesn't exist in my version of Android Studio, and otherwise no code.
The web doesn't offer any solutions for this and I couldn't find any other web forums where I could ask such questions that would be still active today.
My application is written in Kotlin, a supposedly superior and more comfortable language than Java. I'm new to all this and cannot easily convert Java samples to Kotlin. Besides that I can't find any suitable code samples at all.
My understanding is that I need to open an activity which can then request the permission. Unfortunately, the Android developer documentation isn't what I'm used to from Microsoft and doesn't cover creating an activity for a Wear app. And it generally doesn't provide any examples that would show how this method must be called. These are the most helpful parts of a documentation and Android doesn't have that. So I'm quite stuck now. Android wants me do something that I'm unable to figure out how that's possible.
So how is it possible? What Kotlin code do I need to solve this elementary platform issue and request permissions from a watch face service?