我必须从我的Android手机上收集加速度计的数据,所以我做了一个小程序来做到这一点。
经过一些测试后,我发现我的Nexus加速度计的速率是:无论我要求的速率是什么(、UI、GAME或FASTEST),我的Nexus加速度计的速率总是在手机处于活动状态时每秒 50值,而当手机处于休眠状态时则是每秒6值。
因此,我决定安装一个在互联网上找到的应用程序来测试加速度计的速度:http://samoht.fr/tuto/accelerometers-frequency-on-android-with-code
但我也得到了同样的“错误”:无论我要求的速率是多少,当手机处于活动状态时,它总是每秒50个值。
我不明白我的手机为什么会这样。这是否是一个问题:
有关。
编辑:我在另一个Nexus (Android4)上测试了这个程序,我也遇到了同样的问题。因此,它似乎消除了上面列出的一种可能性:它不仅与我的手机有关。
发布于 2012-03-17 08:35:17
我在不同的智能手机上做了一些测试。以下是研究结果:
Samsung Galaxy Teos
-------------------
* When awake
Normal: 4.17 Hz
UI: 8.43 hz
Game: 16.93 Hz
Fastest: 109.42 Hz
* When asleep
The phone sends null values (0), whatever the mode I chose
Samsung Nexus S
---------------
* When awake
Normal: 49.51 Hz
UI: 49.51 hz
Game: 49.51 Hz
Fastest: 49.51 Hz
* When asleep
6.06 Hz, whatever the mode I chose
LG Nexus 5
----------
* When awake
Normal: 15.39 Hz
UI: 15.4 Hz
Game: 50.05 Hz
Fastest: 196.74 Hz
* When asleep
Normal: 4.96 Hz
UI: 15.41 Hz
Game: 50.12 Hz
Fastest: 198.53 Hz
LG Nexus 4
----------
* When awake
Normal: 15.75 Hz
UI: 15.74 Hz
Game: 48.86 Hz
Fastest: 195.85 Hz
* When asleep
Normal: 5.5 Hz
UI: 15.74 Hz
Game: 49.16 Hz
Fastest: 196.75 Hz
Samsung Galaxy Nexus
--------------------
* When awake
Fastest: 125 Hz
* When asleep
It sends data
Samsung Galaxy Note 2
---------------------
* When awake
Fastest: 100 Hz
* When asleep
The phone does not send anything
Samsung Galaxy S3 and S3 Mini
-----------------------------
* When awake
Fastest: 100 Hz
* When asleep
Fastest: 100 Hz
HTC Wildfire
------------
* When awake
Normal: 4 Hz
UI: 12 hz
Game: 22.2 Hz
Fastest: 38.40 Hz
* When asleep
The phone does not send anything, whatever the mode I chose
HTC Desire
----------
* When awake
Normal: 4.36 Hz
UI: 11.9 hz
Game: 23.3 Hz
Fastest: 47.27 Hz
* When asleep
The phone does not send anything, whatever the mode I chose注意到测试是使用部分尾流锁执行的。没有它,Nexus在睡眠时根本不提供任何数据。
还有一个有用的智能手机列表,可以让加速度计在睡觉时发送(或不)兼容数据:http://www.saltwebsites.com/2012/android-accelerometers-screen-off
发布于 2012-03-07 15:33:49
不要将手机通过USB连接到PC上,因为在收集数据的过程中,只记录在SD卡中。当手机通过USB连接到PC机时,SD卡中无法保存任何文件。
因此,在收集数据时,请尝试断开USB。
发布于 2015-07-21 18:46:54
不幸的是,正如其他答案所建议的那样,您设置的延迟(或采样率)仅是应用程序所需最低限度的建议(对于系统),但是,这可能会根据运行的其他应用程序或进入省电模式(关闭cpu等)的设备而发生剧烈变化。我能够获得某种好的采样率的一种方法是记录来自服务的数据,使服务成为前台服务,并使用标志PARTIAL_WAKE_LOCK的电源锁。
我把代码放在这个gist https://gist.github.com/julian-ramos/6ee7ad8a74ee4b442530中
这个gist的代码比您需要的要多得多,但是请注意下面两个方法。
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// //Power management
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Tag");
wl.acquire();
.....}上面的代码阻止操作系统关闭CPU。
现在,要使此服务成为前台服务,请执行以下操作
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(getApplicationContext())
.setContentTitle("Title")
.setContentText("hola")
.setContentIntent(viewPendingIntent);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
not=notificationBuilder.build();
notificationManager.notify(notificationId,not );
startForeground(notificationId, not);上面的代码使服务成为操作系统的优先级,而不是普通的服务。例如,前台服务的例子是音乐播放器。
有了这段代码,我就能得到我所需要的采样率,即使在手表关闭屏幕后也是如此。
https://stackoverflow.com/questions/9358862
复制相似问题