How do you test GPS applications in Android? Can we test it using the Android emulator?
相关问题
- 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
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
Yes.
If you develop using the Eclipse ADT plugin, open the DDMS perspective after launching the emulator and look for the Emulator Control view. There is a location controls section that allows you to send fixed latitude and longitude coordinates, or GPX (GPS Exchange Format) or KML (Keyhole Markup Language) files if you want to send multiple coordinates at regular intervals (to simulate traveling a specific route).
Alternatively, you can simply telnet to the emulator and use the geo command from the command line, which supports fixed latitude and longitude coordinates as well as NMEA data sentences:
In the Extended controls of your emulator (click "..." on the control bar next to your emulator) there is the Location tab, where you can either manually input individual locations (latitude / longitude / altitude) and send them to the virtual device, or setup GPS data playback at a desired speed from a GPX or a KML file you can import.
Edit: it's the default Android Emulator I'm talking about.
in addition to Mallox code this is the sulotion for mock location in addition to real gps location : TEST_MOCK_GPS_LOCATION is a string
in the test class it is :
}
hope it will help you
Maybe you want to a use a Unit test, so you can try this:
For this to work you also need a required permission to the AndroidManifest.xml:
I suggest that you write test which is sending location object to the listener class you want to test. With this in mind you will need some helper methods that will be able to produce location objects.
E.g.:
First you send a location with fixed coordinates (e.g. center of New York).
// test if everything is OK
Than you send a coordinate which is 100m appart from the first coordinate. You can do this with function I implemented recently: https://stackoverflow.com/a/17545955/322791
// test if everything is OK
It is common that GPS methods are related to time. I suggest that you implement method getNow() on listener class and call it whenever you need current time.
In unit test environment you simply set the obj.isUnitTesting=true and obj.unitTestTime to any time you want. After that you can send first location to the listener, then you change time (+x seconds) and send another location ...
It will be much easier to test your application that way.
Perhaps this test application or this can help you.