In using the method below, Android Studio is generating the following error on the keyword "this":
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, MY_PERMISSIONS_REQUEST_READ_FINE_LOCATION);
Error:
Wrong first argument type...found com.websmithing.wp.gpstracker.LocationService, required android.app. Activity
I can reference the activity using "this" without any error when evaluating the manifest file permissions check as per below.
ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
Can anyone point me in the right direction?
this
refers to the present class. It only works withthis
when you are in an activity while requesting permission.Solution
Send a notification from the service so when the user clicks it, open the activity and ask for the permissions you need.
How do I send a notification?
Simple refer to Building a Notification.