Emulator : Allow App to access device location by default - android

I am trying to run automation, is there some way where the App is allowed to access device location by default.
Appreciate your help.

You can store last location in shared preference and use that whenever you want. But for the current location i think it cant happen without user granting permission.

Related

Huawei Android devices - properly requesting permissions for background locations

We develop an application which requires several permissions in order to get the user’s location while in the background.
We are having problems requesting the required permissions on Huawei devices. It seems that in addition to location permission and white listing the app from battery optimizations, an additional step is required in order to disable battery optimizations and enable auto launching:
The problem is we found no way of automatically requesting permission from the user, and the only way we found is having the user manually go to these screens and change the settings.
We did find a shortcut to take us “half way”, to the application settings:
Intent intent = new
Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.parse("package:"+context.getPackageName()));
But multiple non intuitive actions are still required from the user.
Our aim:
We would very much like to make the process easier for the user. Optimally, to have a system dialog appear which asks the user for the permissions, instead of having him manually change the settings, much like the whitelisting of normal Android devices:
Is it possible using a Huawei specific SDK extension?
If (1) is not possible, at the very least we need a way to know if the user changes these settings or not. Currently we don’t know and cannot inform the user if the application works properly or not!
Are you expecting that your app displays a permission popup so that users can easily assign related permissions to your app?
If yes, you can integrate HMS Core Location Kit into your app. Before performing an operation requiring a permission, your app dynamically checks its permissions.
If your app does not have the required permission, it will display a popup to prompt the user to assign the permission. You can implement the popup with few code lines and users can easily assign permissions in the popup. For details, visit https://developer.huawei.com/consumer/en/doc/development/HMS-Guides/location-guidev4.
In addition to dynamic authorization, do not forget to apply for static permissions in the Manifest file.

How to Trap Android Location Permission Revoked after Location Service Started?

I have developed a Android hybrid app that amongst other activities tracks the users location and displays it to the user showing where they have been recently. This works by invoking LocationServices.FusedLocationApi.requestLocationUpdates at a 10 second update rate.
Obviously this requires location permission and for ANDROID Marshmallow and above I check and request the necessary location privileges from the user before requesting location updates.
I have read many other StackOverflow question about the same topic but I have not found a satisfactory answer about preventing Android from terminating the app if location permission is revoked for the app by the user after initially granting it.
I would be more than happy for the app to stop displaying the user's location and track, after all the user has asked for it to be stopped, but I am far less happy for the app to be terminated, as I said earlier the app does many other things for the user whilst running in the background.
As far as I understand there is no callback that can be used to allow me to remove the location updates as soon as the location permission is revoked. How could I change my strategy to avoid the app crashing?
It is not that I am expecting users to do this very often, but I think it good practice to make the app as bulletproof as possible. Please do not remind me that Android can terminate any app in the background as that is not my question here.
Do I need to adopt a singular rather than a periodic approach to requesting the location so that I can re-check the permission exists each time.
Or is it better to try and catch the error. If so where do I do this? Would it be inside onLocationChanged?
What I mean by app crash is that the process is terminated (I have checked and this actually happens)
That's perfectly normal, when the user revokes a runtime permission.
What I would like to do is prevent the process terminating if there is any way I can do this.
Sorry, that is not possible.
Since I suspect that few users even know that they can revoke runtime permissions, this is not going to be a common occurrence, IMHO.
Blockquote
however why did the Android developers not just cause a callback to be generated to allow the app code base to react
You could register for the LocationManager.PROVIDERS_CHANGED_ACTION in the BroadcastReceiver.
When it is hit, you can check if the provider is still enabled and use that accordingly to prevent your app from crashing when someone revokes the location permission.
LocationManager locationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
boolean enabled = locationManager != null && locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

Mock location for specific app only

I want to set mock location for specific app only. So far, what I have understood is, if I set GPS provider with some mock location then, all apps accessing location through GPS will receive mocked location. Can it be made app specific? (means only specific app should see mocked location, all other apps will see true location.) If yes , how?

Android Force Location of Apps

I work in QA for an company that helps market applications. Currently I have been tasked to ensure location dependent apps function if correctly (ie if im in russia the app displays the russian content and if i change to us the app updates to the us content)
I have tried numerous items to accomplish this but get no where.
What i have tried:
Proxy. Setting this up via wifi to several locations. Both the app and the device still show my current location.
Apps: I have tried all of the following apps and they all give the same result as above.
Fake Location
AutoProxy
Fake GPS
I have enabled developer mode on the devices, and have ensured that "Mock Locations" is checked.
Use case 1:
A developer whats us to test his app which is only available in england. Google Play still sees me in US
Use case 2:
A developer releases a game where the background changes based on your location if i cant force the location change I cant verify this feature works.
Im guessing the fails so far are due to the fact that the location being called in our test apps is network location not GPS?
Any help would be awesome. Even if you could just point me in a direction.
Thank you Greatly
J
Update:
Ok, Thanks to the answers about google play and mock locations. So with those in mind lets think about it from another perspective. If the app is not calling for mock location, Is there anyway to force a mock location override? im trying to cover all the bases here, One app for sure does not use this method, so I still need to find a way around.
depending on how they are calling for the location, I would think (remember im knew here) that using a proxy would work, however as stated above, i'm not getting anywhere there either. Did try a few free proxy's from hidemyass but even the browser wouldn't work with them.
Yes, network location does not get faked by mock location providers. I don't know why not, but it only fakes GPS. In addition, your app has to request the MOCK permission to get it. If it doesn't have this permission, setting a mock location will not actually fake anything to the app. This is for security purposes, so a malicious app can't start broadcasting the wrong location to the phone.

How to get user's location?

I want to get user's location in my app. So, I read documentations and know how to get it work. But, if user haven't set "Alloy apps to use internet/GPS to get location" in preferences, my app crashes.
The only way I found is to show dialog that location settings are not enabled and to go programmaticaly to location preferences.
But is there another way to solve this? I saw many apps (like yandex.maps) that do not request this settings being enabled.
well, your app should not install if the user doesn't agree to the terms of use, and allow the permissions requested.
still you should check to see that there's a way to look the information up when you want it.
in your code, before the actual test for user's location, you should probably call a function that checks for all the location manager listings, and return false if there's no way to determine this.
if the function returns false, you should prompt the user and do nothing. else, you should do what it is you're trying to do.
try reading vogella's tutorial about using location manager
Refer this two links below and you might get your answer easily.
How do I get the current GPS location programmatically in Android?
android - how to get current location latitude and longitude
Hope it will help you.

Categories

Resources