How do I set custom/mock location in Android?
-
I have made an App that shows up location searched by the user.Now I want to set this location as the current location in such a way that the Android system assumes that this particular location is the current location.Now whatever the apps(Fb,Twitter,Quora... Etc) installed in a device must read this location as current location.How do I achieve this?
-
Answer:
I don't think what you want here is mock locations. If you want apps to assume you are at a particular location then its not the GPS location that apps like google or play store use for location detection. Apps use your IP for that. Using IP makes it very easy and generic since everyone will have one, unlike GPS which can be disabled with a single click. You can mask your location using VPN. Try Tunnel bear for starters, simple and quick. You can make different profiles to mask your IP.
Abhimanyu Bhosale at Quora Visit the source
Other answers
As far as I am aware, you can only set the mock location for your own app, not all apps on the device. To test your app with mock locations, you can follow the tutorial here - http://developer.android.com/training/location/location-testing.html
Lata Sadhwani
Does this work for above requirement? private void setMockLocation(double latitude, double longitude, float accuracy) { lm.addTestProvider (LocationManager.GPS_PROVIDER, "requiresNetwork" == "", "requiresSatellite" == "", "requiresCell" == "", "hasMonetaryCost" == "", "supportsAltitude" == "", "supportsSpeed" == "", "supportsBearing" == "", android.location.Criteria.POWER_LOW, android.location.Criteria.ACCURACY_FINE); Location newLocation = new Location(LocationManager.GPS_PROVIDER); newLocation.setLatitude(latitude); newLocation.setLongitude(longitude); newLocation.setAccuracy(accuracy); lm.setTestProviderEnabled(LocationManager.GPS_PROVIDER, true); lm.setTestProviderStatus(LocationManager.GPS_PROVIDER,LocationProvider.AVAILABLE,null,System.currentTimeMillis()); lm.setTestProviderLocation(LocationManager.GPS_PROVIDER, newLocation); } ** lm is an object of LocationManager **
Anonymous
We at http://www.testmunk.com did a writeup on how you can mock the location on Android devices and run automated tests. It involves the following steps: Preparing the build - add âaccess mock locationâ in your manifest file - set debuggable to true Change device settings to âAllow mock locationâ Write a teststep that involves longitude and latitude, for example using the calabash automation franework: Then /^I am at ([-+]?[0-9]*\.?[0-9]+), ([-+]?[0-9]*\.?[0-9]+)$/ do |latitude, longitude| set_gps_coordinates(latitude, longitude) end The whole writeup you will find here: http://blog.testmunk.com/testing-location-mocking-on-android-devices-calabash-open-source/ and hereâs the open source github repo: https://github.com/testmunk/calabash-location-mocking Don't hesitate to reach out if you have any questions!
Martin Poschenrieder
After you allowed mock locations and if you want to go the appium route instead of calabash route as explained by below. Use this code sample for https://github.com/appium/appium/blob/e6927c60e2264e32eade441dbfbf57f183310b43/test/functional/android/gpsdemos/location-specs.js#L45 JS
Satyajit Malugu
Related Q & A:
- How do I add custom attributes to javascript tags in Wordpress?Best solution by WordPress
- How can I get custom fields in wordpress?Best solution by Stack Overflow
- How do I disable the previous dates in Android custom calendar?Best solution by Stack Overflow
- How do I set up my set top box?Best solution by Server Fault
- How do I change the original location on My Yahoo Weather?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.