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
This worked for me (Android Studio):
Disable GPS and WiFi tracking on the phone. On Android 5.1.1 and below, select "enable mock locations" in Developer Options.
Make a copy of your manifest in the src/debug directory. Add the following to it (outside of the "application" tag):
uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"
Set up a map Fragment called "map". Include the following code in onCreate():
Note that you may have to temporarily increase "minSdkVersion" in your module gradle file to 17 in order to use the "setElapsedRealtimeNanos" method.
Include the following code inside the main activity class:
Run your app with AS. On Android 6.0 and above you will get a security exception. Now go to Developer Options in Settings and select "Select mock location app". Select your app from the list.
Now when you tap on the map, onLocationChanged() will fire with the coordinates of your tap.
I just figured this out so now I don't have to tramp around the neighborhood with phones in hand.