0

I am currently on android SDK level 29. (Android 10/11)

In my android manifest I grant permissions as such:

    <uses-permission android:name="android.permission.BLUETOOTH"/>
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

I also grant location permissions for MainActivity, which is the parent activity for the fragment that uses user location data as such:

    <application>

        <service
            android:name=".ui.MainActivity"
            android:foregroundServiceType="location"/>

    </application>

However, Compiler still says I am "MISSING_PERMISSION_ACCESS_COARSE_LOCATION"

Does this have something to do with the user having to grant location permissions in the runtime? Also, the reason I need such permissions is for Google Nearby API, which might also need separate background location permissions.

However, as far as my knowledge goes, after adding the two pieces of code above in the Android Manifest, background location permissions should also be granted.

What could be the problem here?

Ian
  • 7
  • 5
  • 2
    you should get runtime permission after android M look at this link: https://stackoverflow.com/questions/30549561/how-to-check-grants-permissions-at-run-time – saeedata Jan 16 '21 at 14:19
  • did you include the code for permissions check in you activity – Taki Jan 16 '21 at 14:32
  • `MainActivity` is an `activity` or `service`? – rahat Jan 16 '21 at 14:47
  • @takieddine No. All I do is call Google Nearby API Functions which require location permissions. – Ian Jan 16 '21 at 15:06
  • @rahat MainActivity is just an Activity that is the parent activity to many fragments. (Many fragments are stacked on top of the base MainActivity, and in one of those fragments, location permission is needed.) – Ian Jan 16 '21 at 15:07
  • 1
    Then why you declared it in `service` tag in `manifest`, it should be `` tag – rahat Jan 16 '21 at 15:09
  • I changed `` to `` but permission is still missing... – Ian Jan 16 '21 at 15:21
  • you have to know that you need to check for background location in andoid 10 and up , did you do that in your fragment ! – Taki Jan 16 '21 at 15:40
  • Ah-ha! I have just found out that I need to request location permissions in the runtime. I think my real question was how to do so, even the official documentation: https://developer.android.com/training/location/permissions does not show how to do so. – Ian Jan 16 '21 at 16:09

0 Answers0