Android detects only mock locations? - android

I am making an app in which I want to get the users' location to show on a map. When I am running the app on a real device, it does not seem to get this location, but it gets locations if I put in mock locations using a GPS location faker. In the emulator these mock locations are also detected.
How can I get my phone to get the real location too?

Requesting User Permissions In order to receive location updates from
NETWORK_PROVIDER or GPS_PROVIDER, you must request the user's
permission by declaring either the ACCESS_COARSE_LOCATION or
ACCESS_FINE_LOCATION permission, respectively, in your Android
manifest file. Without these permissions, your application will fail
at runtime when requesting location updates.
If you are using both NETWORK_PROVIDER and GPS_PROVIDER, then you need
to request only the ACCESS_FINE_LOCATION permission, because it
includes permission for both providers. Permission for
ACCESS_COARSE_LOCATION allows access only to NETWORK_PROVIDER.
Read more at https://developer.android.com/guide/topics/location/strategies.html#Permission

Related

Location Permissions on Android

I know there are two different types of location permissions
ACCESS_COURSE_LOCATION
ACCESS_FINE_LOCATION
I know that for using the location from Android M, we require runtime permission form the User. Now the issue is that both ACCESS_COURSE_LOCATION and ACCESS_FINE_LOCATION falls under the same bucket and which implies that granting one runtime permission will grant the other one without asking the user.
So, now my doubt is that if I just ask ACCESS_COURSE_LOCATION permission and still can have the ACCESS_FINE_LOCATION then why should I need to request ACCESS_FINE_LOCATION? Can I just get a fine location with just ACCESS_COURSE_LOCATION location permission?
Also, I am requesting a location fix with the below criteria
Criteria criteria = new Criteria();
criteria.setBearingAccuracy(Criteria.ACCURACY_MEDIUM);
criteria.setPowerRequirement(Criteria.POWER_MEDIUM);
riteria.setCostAllowed(false);
So how do the two different permissions affect the location fix I am getting with the above criteria?.
EDIT 1: Rephrasing the question. I know about the different providers like GPS, network, etc. and which permission they require. That's why my doubt is that if granting ACCESS_COURSE_LOCATION can result in granting ACCESS_FINE_LOCATION. Then can we have a situation during app lifecycle where we have only ACCESS_COURSE_LOCATION granted? Also, how would the above criteria behave?
EDIT 2: Few other StackOverflow answers says that ACCESS_COURSE_LOCATION can be eliminated when ACCESS_FINE_LOCATION is granted. But if I just want a course location, I request permission and then I request location fix using the above criteria. So what should I expect a course location or a fine location? as granting course location is internally granting the fine location permission as well.

Android Permissions and API Calls

can two different api calls each requiring a different permission produce the same results?
e.g. to get device coarse location, from Android documentation, it is an approximate location derived from network location.. can an app retrieve network location using another api call that does not require ACCESS_COARSE_LOCATION permission?
In other words, according to Android documentation, regarding LocationManager, "A location provider provides periodic reports on the geographical location of the device....some providers require GPS hardware and visibility to a number of satellites; others require the use of the cellular radio, or access to a specific carrier's network, or to the internet" and all requires either ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permissions.
if an app doesn't ask for these permissions yet it asks for ACCESS_NETWORK_STATE, ACCESS_WIFI_STATE, and INTERNET can the app infer location? if so, what API calls are responsible for this to happen, I read the API guide, connectivity part, and searched the classes under android.net.wifi but could not find what would create such situation.
is there any work or a resource that groups Android api calls by required permissions?? e.g. a list of all api calls under ACCESS_COARSE_LOCATION permission, a list of all api calls under ACCESS_FINE_LOCATION permission and so on!
Hope I clearly asked my questions and thanks in advance!
According to the documentation:
Note: If you are using both NETWORK_PROVIDER and GPS_PROVIDER, then you need to request only the ACCESS_FINE_LOCATION permission, because it includes permission for both providers. (Permission for ACCESS_COARSE_LOCATION includes permission only for NETWORK_PROVIDER.)
You should take in consideration that coarse location (battery friendly) is not so precise as fine location (not battery friendly), AND usually they are required both because a user can decide to enable from device network location and disable GPS, it's your duty to optimize your app so it will not kill the battery. Information from above (and more about location) can be found here http://developer.android.com/guide/topics/location/strategies.html
the previous link has some explanations about the location, with some examples.
And for future reference, you might find this table useful http://developer.android.com/guide/topics/manifest/uses-feature-element.html#features-reference

If I have ACCESS_FINE_LOCATION already, can I omit ACCESS_COARSE_LOCATION?

I have a GPS app that already requests ACCESS_FINE_LOCATION permission in the manifest, now I want to add a library (MoPub) that requires ACCESS_COARSE_LOCATION.
Am I correct in assuming that ACCESS_FINE_LOCATION is enough, and I can leave out ACCESS_COARSE_LOCATION from my manifest?
https://developer.android.com/guide/topics/location/strategies.html#Permission
Note: If you are using both NETWORK_PROVIDER and GPS_PROVIDER, then you need to request only the ACCESS_FINE_LOCATION permission, because it includes permission for both providers. (Permission for ACCESS_COARSE_LOCATION includes permission only for NETWORK_PROVIDER.)
In short: yes, you don't need ACCESS_COARSE_LOCATION if you've already defined ACCESS_FINE_LOCATION.
Depends on your needs.
Permission wise, ACCESS_FINE_LOCATION includes ACCESS_COARSE_LOCATION. However, there is a catch:
ACCESS_COARSE_LOCATION gives you last-known location which is battery friendly
https://developer.android.com/training/location/retrieve-current.html#setup
For example, if your app does something like location-based recommendations, last-known location is good enough.
This has a dependency on Google Play Services
However, if you need something like live/ real-time location like Pokemon Go, use ACCESS_FINE_LOCATION
It gives you live/ real-time location. You'll need to use a LocationListener
Last time I checked, this does not require Google Play Services
Update
On Android 12 (API level 31) or higher, users can request that your app retrieve only approximate location information, even when your app requests the ACCESS_FINE_LOCATION runtime permission.
To handle this potential user behavior, don't request the ACCESS_FINE_LOCATION permission by itself. Instead, request both the ACCESS_FINE_LOCATION permission and the ACCESS_COARSE_LOCATION permission in a single runtime request. If you try to request only ACCESS_FINE_LOCATION, the system ignores the request on some releases of Android 12.
Check this url: https://developer.android.com/training/location/permissions#approximate-request
Difference:
https://developer.android.com/training/location/permissions#accuracy
https://developer.android.com/training/location/permissions#approximate-request
You need to ask for both permissions.
Approximate
Provides an estimate of the device's location, to within about 1 mile (1.6 km). Your app uses this level of location accuracy when you
declare the ACCESS_COARSE_LOCATION permission but not the
ACCESS_FINE_LOCATION permission. Precise
Provides an estimate of the device's location that is as accurate as possible, usually within about 160 feet (50 meters) and sometimes
as accurate as within 10 feet (a few meters) or better. Your app uses
this level of location accuracy when you declare the
ACCESS_FINE_LOCATION permission.
If the user grants the approximate location permission, your app only
has access to approximate location, regardless of which location
permissions your app declares.
Your app should still work when the user grants only approximate
location access. If a feature in your app absolutely requires access
to precise location using the ACCESS_FINE_LOCATION permission, you can
ask the user to allow your app to access precise location. ``
Then in Android 12 permission changes
On Android 12 (API level 31) or higher, users can request that your
app retrieve only approximate location information, even when your app
requests the ACCESS_FINE_LOCATION runtime permission.
To handle this potential user behavior, don't request the
ACCESS_FINE_LOCATION permission by itself. Instead, request both the
ACCESS_FINE_LOCATION permission and the ACCESS_COARSE_LOCATION
permission in a single runtime request. If you try to request only
ACCESS_FINE_LOCATION, the system ignores the request on some releases
of Android 12.

Get *coarse* location from GPS provider on Android

My app only needs very rough location data, so I originally set my manifest permissions to ACCESS_COARSE_LOCATION, and set up a location listener for NETWORK_PROVIDER. This gave me exactly the kind of rough location estimate I needed, but only with Google Location Services turned on.
I was expecting that if the user only had GPS enabled, that I would still receive a rough estimate of their location. But it seems like the only way to get ANY location information from the GPS_PROVIDER is by using the ACCESS_FINE_LOCATION permission.
So, is it true that with only GPS enabled, an app cannot receive location information unless it has the ACCESS_FINE_LOCATION permission? In other words, the GPS_PROVIDER can't send rough location estimates if the app only has ACCESS_COARSE_LOCATION permission?
So, is it true that with only GPS enabled, an app cannot receive location information unless it has the ACCESS_FINE_LOCATION permission?
Generally speaking, yes.
Quoting the documentation for LocationManager:
If your application only has the coarse permission then it will not have access to the GPS or passive location providers. Other providers will still return location results, but the update rate will be throttled and the exact location will be obfuscated to a coarse level of accuracy.
In other words, the GPS_PROVIDER can't send rough location estimates if the app only has ACCESS_COARSE_LOCATION permission?
Quoting the Android 4.2 release notes:
Compared to previous versions of Android, user location results may be less accurate if your app requests the ACCESS_COARSE_LOCATION permission but does not request the ACCESS_FINE_LOCATION permission.
To meet the privacy expectations of users when your app requests permission for coarse location (and not fine location), the system will not provide a user location estimate that’s more accurate than a city block.
However, I am assuming that this does not supersede the "will not have access to the GPS" statement from LocationManager. I assume that this means that NETWORK_PROVIDER data might be inhibited, if it is deemed too accurate.

Will Android still use GPS to pull location when only COARSE_LOCATION is requested?

I am trying to figure out if I really need to request ACCESS_FINE_LOCATION or not. I do not need really accurate coordinates. However, if cell towers or WiFi is not available, I want to be able to get a location from GPS (low accuracy is fine). But, I cannot find a clear answer in the Android documentation about this. Below is what the Android Docs say (ACCESS_COARSE_LOCATION). It tells me that requesting the coarse location gives me info from the "Cell-ID, WiFi" source and that requesting the fine permission will use GPS, but it says nothing about GPS being any type of fallback for when only the coarse location permission is requested.
public static final String ACCESS_COARSE_LOCATION
Since: API Level 1
Allows an application to access coarse (e.g., Cell-ID, WiFi) location
Constant Value: "android.permission.ACCESS_COARSE_LOCATION"
public static final String ACCESS_FINE_LOCATION
Since: API Level 1
Allows an application to access fine (e.g., GPS) location
Constant Value: "android.permission.ACCESS_FINE_LOCATION"
I think this other post and the Android documentation it references answers this question. The Android doc says the following.
Note: If you are using both NETWORK_PROVIDER and GPS_PROVIDER, then you need to request only the ACCESS_FINE_LOCATION permission, because it includes permission for both providers. (Permission for ACCESS_COARSE_LOCATION includes permission only for NETWORK_PROVIDER.)
So, if I'm reading that right, requesting ACCESS_COARSE_LOCATION can't pull from GPS because it does not request access for the GPS_PROVIDER.

Categories

Resources