【发布时间】:2011-02-23 00:27:45
【问题描述】:
有没有办法在安卓模拟器上模拟速度?
[编辑] 这样做的目的是为了测试getSpeed()方法
示例: 我想设置设备以每小时 20 英里的速度行驶。
【问题讨论】:
-
你能指定“模拟速度”吗?
-
我所说的速度是设备的运动速率。
有没有办法在安卓模拟器上模拟速度?
[编辑] 这样做的目的是为了测试getSpeed()方法
示例: 我想设置设备以每小时 20 英里的速度行驶。
【问题讨论】:
Location 对象有一个方法来设置设备的速度:
//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)
如果您想模拟一段时间内的速度变化,您可以设置一个计时器并在该时间段内降低或提高速度,例如:
int secondsDelayed = 5;
new Handler().postDelayed(new Runnable() {
public void run() {
location.setSpeed((float) 50.0);
}
}, secondsDelayed * 1000);
这将在 5 秒内将速度提高到 50 km/p
【讨论】:
我的高配置电脑 3i 4GB 也遇到了同样的问题,但是模拟器运行速度很慢
我找到了一些对我有用的东西,希望它对其他人有用,我很乐意在这里分享它
我刚刚将Device ram size 添加到我现有的AVD 并设置size to 1000MB(因为我有足够的空间来分配4GB)
不,我的AVD 的速度是最终希望它可以帮助你。
【讨论】:
是的,您可以这样做。如果您使用 Eclipse 开发您的应用程序,您必须转到 DDMS 透视图。在那里你应该找到一个名为 Emulator control 的窗口。在此窗口中,您可以将新的地理位置(GPS 坐标)发送到您的模拟器或设备。当您想提高速度时,最好使用 GPX 或 KML 文件。在此文件中,您可以定义 GPS 坐标,然后逐步读取这些坐标。通过适当地选择这个坐标,您可以模拟一个恒定的速度。
【讨论】: