我必须从 Android 手机收集加速度计数据,因此我编写了一个小程序来做到这一点。
经过一些测试,我发现我的 Nexus S 加速计的速率在手机处于活动状态时始终每秒 50 个值,在睡眠状态时每秒始终 6 个值(使用 PARTIAL_WAKE_LOCK code>),无论我要求什么速率(NORMAL
、UI
、GAME
或 FASTEST
)。
所以我决定安装一个在互联网上找到的应用程序来测试加速度计的速率: http://samoht.fr/tuto/accelerometers-Frequency-on-android-with-code
但我得到了同样的“错误”:无论我要求的速率是什么,它总是 50 个值当手机处于活动状态时每秒。
我不明白为什么我的手机会这样。这是一个问题:
- 与 Nexus S 有关吗?
- 具体到我的手机?
- 与Android 4有关?
编辑:我已经在另一台Nexus S(Android 4)上测试了该程序,并且遇到了同样的问题。
所以它似乎消除了上面列出的可能性之一:它不仅仅与我的手机有关。
I have to collect accelerometer data from my Android phone, so I have made a little program to do that.
After some tests, I have found that my Nexus S accelerometer's rate is always 50 values per second when the phone is active, and 6 values per second when it is asleep (with a PARTIAL_WAKE_LOCK
), whatever the rate I ask for (NORMAL
, UI
, GAME
or FASTEST
).
So I decided to install an application found on the Internet which tests the rate of the accelerometer : http://samoht.fr/tuto/accelerometers-frequency-on-android-with-code
But I got the same "error" : whatever the rate I ask for, it is always 50 values per second when the phone is active.
I don't understand why my phone behaves this way. Is it a problem :
- related to the Nexus S ?
- specific to my phone ?
- related to Android 4 ?
EDIT : I have tested the program on another Nexus S (Android 4), and I have the same problem.
So it seems to eliminate one of the possibilities listed above: it is not related only to my phone.
发布评论
评论(4)
我在不同的智能手机上进行了一些测试。以下是结果:
请注意,测试是使用部分唤醒锁执行的。如果没有它,Nexus S 在睡眠时根本不提供任何数据。
还有一个有用的智能手机列表,加速计在睡眠时发送(或不发送)兼容数据:http://www.saltwebsites.com/2012/android-accelerometers-screen-off
I have performed some tests on different smartphones. Here are the results:
Note that the tests have been performed using a partial wake lock. Without it, the Nexus S provides no data at all when it is asleep.
There is also a useful list of smartphones which accelerometers send (or not) compatible data when asleep: http://www.saltwebsites.com/2012/android-accelerometers-screen-off
采集数据时请勿通过 USB 将手机连接到 PC,因为在采集过程中数据仅记录在 SD 卡中。当手机通过 USB 连接到 PC 时,SD 卡中无法保存文件。
因此,请尝试在收集数据时断开 USB 连接。
Don't connect your phone to a PC via USB while taking data because during collection data is logged in the SD card only. When the phone is connected to PC via USB no file can be saved in SD card.
So try disconnecting the USB while collecting the data.
不幸的是,正如其他答案所建议的,您设置的延迟(或采样率)只是应用程序所需的最小值的建议(对于系统),但是,这可能会根据其他应用程序运行或您的设备进入省电模式而发生巨大变化模式(关闭CPU等)。我能够获得较好采样率的一种方法是记录来自服务的数据,使该服务成为前台服务,并使用带有 PARTIAL_WAKE_LOCK 标志的电源锁。
我把代码放在这个要点中
https://gist.github.com/julian-ramos/6ee7ad8a74ee4b442530
这个要点有办法代码比您需要的更多,但只需注意接下来的两个方法
上面的代码阻止操作系统关闭 CPU
现在使该服务成为前台服务
与普通服务不同,上面的代码使该服务成为操作系统的优先级。前台服务的示例是音乐播放器。
通过这段代码,即使手表自动关闭屏幕后,我也能够获得所需的采样率。
Unfortunately as suggested by other answers, the delay (or sampling rate) that you set is only a suggestion (for the system) of the minimum your application requires however, this can change drastically depending on other applications running or your device entering on power saving modes (turning off cpu etc). One way I was able to get a somewhat good sampling rate was by recording my data from a service, making the service a foreground service and having a power lock with the flag PARTIAL_WAKE_LOCK.
I put the code in this gist
https://gist.github.com/julian-ramos/6ee7ad8a74ee4b442530
That gist has way more code than you need but just pay attention to the next two methods
The above code prevents the OS to turn off the CPU
Now to make this service a foreground service
The above code makes the service a priority for the OS unlike a normal service. Examples of a foreground service are music players for instance.
With this code I have been able to get the sampling rate I need even after the watch turn's off the screen automatically.
检查这个应用程序
无论设备型号如何,我们都将采样频率固定为 14-15 https://market.android.com/details?id=singh.pal.ajeet&feature=search_result#?t=W251bGwsMSwxLDEsInNpbmdoLnBhbC5hamVldCJd
如需任何帮助,请发送电子邮件至 [电子邮件受保护]
check this app
we have fixed sampling frequency at 14-15 irrespective of device model https://market.android.com/details?id=singh.pal.ajeet&feature=search_result#?t=W251bGwsMSwxLDEsInNpbmdoLnBhbC5hamVldCJd
for any assistance mail us at [email protected]