How to simulate speed on Android emulator?

我与影子孤独终老i 提交于 2020-01-06 01:58:19

问题


Is there a way to simulate speed on Android emulator?

[edit] The purpose of this to test the getSpeed() method

Example: I would like to set the device is going at 20 miles an hour.


回答1:


Yes you can do that. If your using Eclipse to develop your app, you have to go to the DDMS perspective. There you should find a window called Emulator control. In this window you can send new geo locations (GPS coordinates) to your emulator or device. As you want to emaulte speed its better to use GPX or KML files. In this files you can define GPS coordinates and these coordinates are then read step by step. By choosing this coordinates appropriately you can simluate a constant speed.




回答2:


The Location object has a method to set the speed of the device:

//the instance
Location location;

//retrieves the speed of the device
location.getSpeed()

// set the speed of the device of course for testing purporses, remember to
// remove this when deploying your appplication
location.setSpeed((float) 20.0)

If you want to simulate a change of speed over a time you can set a timer and decrease or increase the speed in that span of time, for example:

int secondsDelayed = 5;
new Handler().postDelayed(new Runnable() {
    public void run() {
        location.setSpeed((float) 50.0);
    }
}, secondsDelayed * 1000);

This will incrase the speed to 50 km/p over a span of 5 seconds




回答3:


I've faced the same problem with my high config pc have 3i 4GB , but the emulator works so slow I found something that worked for me and hope it may work for others i would love to share it here

i've just added Device ram size to My existing AVD and set the size to 1000MB(Because i've enough to allot mind 4GB) No the speed of my AVD was ultimate hope it may help you.



来源:https://stackoverflow.com/questions/2893423/how-to-simulate-speed-on-android-emulator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!