Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There should be permission Allow All time #58

Closed
ramay2088 opened this issue Mar 5, 2022 · 18 comments
Closed

There should be permission Allow All time #58

ramay2088 opened this issue Mar 5, 2022 · 18 comments

Comments

@ramay2088
Copy link

ramay2088 commented Mar 5, 2022

Describe the bug
I have to give allow all time permission for android to keep it working in bacckground. but this plugin allow only while using app. How i can overcome this issue. If I give while using app permssion it is not working in background

To Reproduce
Steps to reproduce the behavior:
just put application in background on call http request on location change

Expected behavior
it should work all time while in bacgkround or minimize

Smartphone (please complete the following information):

  • Pocko
    -Android 12
@diachedelic
Copy link
Collaborator

You may be experiencing #14, whereby HTTP requests made from the WebView are throttled in the background.

@DanaStefanoska
Copy link

I tried this plugin and it's not #14, I've also added that http. Once I manually go to app info and set the permissions to always, I start getting locations when app is in the background and it's sent just fine.
The problem that the OP wants to say is when we request permissions the only 3 choices are "Allow only while using app", "Ask every time" and "Don't allow", the missing one that we need is "Allow all the time".

I tried updating permissions to have ACCESS_BACKGROUND_LOCATION but it still didn't ask for it when asking for permissions.
Note: Protection level is dangerous for this permission so that might be the problem.

@diachedelic
Copy link
Collaborator

Which versions of Android do you see this problem on?

@DanaStefanoska
Copy link

I'm testing on Pixel 6, Android version 12

@diachedelic
Copy link
Collaborator

If anyone discovers a solution please let me know.

@klantz81
Copy link

I was confused about this as well, but I found this text at https://developer.android.com/training/location/permissions

On Android 11 (API level 30) and higher, however, the system dialog doesn't include the Allow all the time option. Instead, users must enable background location on a settings page, as shown in figure 7.

@klantz81
Copy link

klantz81 commented Apr 18, 2022

It looks like this plugin is using a foreground service to access the location rather than require the ACCESS_BACKGROUND_LOCATION permission, so you don't have the option to allow all the time. As long as the app is running even in the background, the foreground service should continue to access the location without the ACCESS_BACKGROUND_LOCATION permission, correct?

Edit: I found some more information here on when ACCESS_BACKGROUND_LOCATION is required if using a foreground service: https://developer.android.com/guide/components/foreground-services

Another edit: According to the documentation you should only need ACCESS_BACKGROUND_LOCATION if the foreground service is started by an app running in the background, but I'm not having any luck without adding location access all the time.

@diachedelic
Copy link
Collaborator

diachedelic commented Apr 19, 2022

At least on Android 11, the "Allow only while using app" permission is sufficient to provide both foreground and background location updates. The confusion arises from the wording of the permission dialog. This wording is especially confusing if you are familiar with the permissions dialog on iOS, which uses similar wording but for a different permissions model. It is crucial to understand what is meant by "background" on both platforms.

As far as Android is concerned, so long as a persistent notification is visible then the user is actively using the app, even if the app itself is not visible. It remains in the foreground in some sense. Android's permissions dialog gives the user three options:

  • While using the app
  • Only this time
  • Don't allow

Selecting either of the first two will be sufficient for granting "background" location updates.

The ACCESS_BACKGROUND_LOCATION permission (which this plugin does not use) is more powerful. It allows the app to access the device's location at any time, without informing the user. That is why Android is so reluctant to grant it.

iOS, on the other hand, uses a more intuitive permissions model. It considers the app to be backgrounded if it is not visible on the screen. Before an app can receive background locations updates, the user must choose from the following:

  • Allow while using the app
  • Allow once
  • Don't allow

Choosing "Allow while using the app" will result in foreground location updates only. The next time the user sends the app to the background, they will be prompted to upgrade the permission to include background updates. The "Allow once" option provides both foreground and background location updates, but only until the app is killed.

@diachedelic diachedelic pinned this issue Apr 19, 2022
@klantz81
Copy link

Hey.. I just wanted to follow up because the others may be having the same issue I was. In the device log I was seeing this message: Foreground service started from background can not have location/camera/microphone access

Which is why the ACCESS_BACKGROUND_LOCATION was being required. It seems by the time the onActivityStopped() method is called, the app is already in the background, so the isLocationAvailable() method was returning false. Once I removed the onActivityStarted() and onActivityStopped() methods and started the foreground service when the watcher is created in addWatcher(), I'm starting to get consistent location updates.

@diachedelic
Copy link
Collaborator

What device and OS are you using @klantz81 ? When you start the foreground service I suppose the notification is presented even whilst the app is visible?

@diachedelic
Copy link
Collaborator

If you rename the handleOnStop method to handleOnPause, is the foreground service able to start?

@klantz81
Copy link

I'm using a pixel 6 pro with android 12. Yes, when I start the foreground service in the LocalBinder::addWatcher method, the notification is presented while the app is visible.

If I change the plugin methods to handleOnPause/handleOnResume, the foreground service is able to provide location updates when the app is in the background, and the notification is not presented until I put the app in the background.

@diachedelic
Copy link
Collaborator

Thanks @klantz81 . This fix is released in v1.2.1 and v0.3.16, please test.

@klantz81
Copy link

I've checked v1.2.1, and it's working fine. Thank you!

@jadsy2107
Copy link

request permissions on ios does not work after the initial request is responded with 'Don't Allow'

`  async requestLocPermissions() {
    const request = await Geolocation.requestPermissions();
    console.log(request);
  }`

native Geolocation.requestPermissions(#ID)
result Geolocation.requestPermissions(#ID) (not false)
{coarseLocation: "denied", location: "denied"}

No iOS native pop up asking for permissions, (allow, dont allow)
Maybe ios has no way of allowing the permissions after they are denied,
closing the app reopening doesnt help
you have to delete the app to request permissions again

@diachedelic
Copy link
Collaborator

I think you are using a different plugin, @jadsy2107 . See https://github.com/ionic-team/capacitor-plugins/tree/main/geolocation. However, your problems might be solved by swapping to this plugin.

@blinkdagger182
Copy link

blinkdagger182 commented Mar 28, 2023

include this in your build AndroidManifest.xml file

<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

inside the manifest tag and you should be good to go

@jongbonga
Copy link

include this in your build AndroidManifest.xml file

<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

inside the manifest tag and you should be good to go

I have had this on my Manifest for the longest but it doesn't work, Sentry always report this issue

ACCESS_BACKGROUND_LOCATION: not_granted, 
ACCESS_COARSE_LOCATION: granted, 
ACCESS_FINE_LOCATION: granted, 
ACCESS_NETWORK_STATE: granted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants