How can I mock my location on a physical device (Nexus One)? I know you can do this with the emulator in the Emulator Control panel, but this doesn't work for a physical device.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- How to replace file-access references for a module
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
Use this permission in manifest file
android studio will recommend that "Mock location should only be requested in a test or debug-specific manifest file (typically src/debug/AndroidManifest.xml)" just disable the inspection
Now make sure you have checked the "Allow mock locations" in developer setting of your phone
Use LocationManager
Now set the location wherever you want
I've had success with the following code. Albeit it got me a single lock for some reason (even if I've tried different LatLng pairs), it worked for me.
mLocationManager
is aLocationManager
which is hooked up to aLocationListener
:What Dr1Ku posted works. Used the code today but needed to add more locs. So here are some improvements:
Optional: Instead of using the LocationManager.GPS_PROVIDER String, you might want to define your own constat PROVIDER_NAME and use it. When registering for location updates, pick a provider via criteria instead of directly specifying it in as a string.
First: Instead of calling removeTestProvider, first check if there is a provider to be removed (to avoid IllegalArgumentException):
Second: To publish more than one location, you have to set the time for the location:
There also seems to be a google Test that uses MockLocationProviders: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/1.5_r4/android/location/LocationManagerProximityTest.java
Another good working example can be found at: http://pedroassuncao.com/blog/2009/11/12/android-location-provider-mock/
Another good article is: http://ballardhack.wordpress.com/2010/09/23/location-gps-and-automated-testing-on-android/#comment-1358 You'll also find some code that actually works for me on the emulator.
I wonder if you need the elaborate Mock Location setup. In my case once I got a fix location I was calling a function to do something with that new location. In a timer create a mock location. And call the function with that location instead. Knowing all along that in a short while GPS would come up with a real current location. Which is OK. If you have the update time set sufficiently long.
Install Fake GPS app https://play.google.com/store/apps/details?id=com.incorporateapps.fakegps.fre&hl=en
Developer options -> Select mock location app(It's mean, Fake location app selected).
Fake GPS app:
Double tab on the map to add -> click the play button -> Show the toast "Fake location stopped"
finally check with google map apps.
I wrote an App that runs a WebServer (REST-Like) on your Android Phone, so you can set the GPS position remotely. The website provides an Map on which you can click to set a new position, or use the "wasd" keys to move in any direction. The app was a quick solution so there is nearly no UI nor Documentation, but the implementation is straight forward and you can look everything up in the (only four) classes.
Project repository: https://github.com/juliusmh/RemoteGeoFix