[英]Impossibility to change the rate of the accelerometer
我必须从我的Android手机中收集加速度计数据,因此我做了一个小程序来做到这一点。
经过一些测试,我发现我的Nexus S加速度计在手机处于活动状态时的速率始终为每秒50个值,在睡眠状态下(使用PARTIAL_WAKE_LOCK
) 始终为每秒6个值,无论我要求的速率如何( NORMAL
, UI
, GAME
或FASTEST
)。
因此,我决定安装一个在Internet上找到的用于测试加速度计速率的应用程序: http : //samoht.fr/tuto/accelerometers-frequency-on-android-with-code
但是我遇到了同样的“错误”:无论我要求的速率如何,当电话处于活动状态时,每秒总是50个值。
我不明白为什么我的手机会出现这种情况。 这是个问题吗 :
编辑 :我已经在另一个Nexus S(Android 4)上测试了该程序,并且遇到了同样的问题。 因此,似乎消除了上面列出的一种可能性:它不仅与我的手机有关。
我在不同的智能手机上进行了一些测试。 结果如下:
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 S处于休眠状态时将完全不提供任何数据。
还有一个智能手机的有用列表,这些智能手机在睡眠时会发送(或不发送)兼容数据: http : //www.saltwebsites.com/2012/android-accelerometers-screen-off
进行数据传输时,请勿通过USB将手机连接到PC,因为在收集数据时,数据仅记录在SD卡中。 通过USB将手机连接到PC时,无法在SD卡中保存文件。
因此,在收集数据时尝试断开USB连接。
不幸的是,正如其他答案所建议的那样,您设置的延迟(或采样率)仅是(对于系统而言)应用程序所要求的最小值的建议,但是,这可能会根据正在运行的其他应用程序或设备进入节电状态而发生巨大变化模式(关闭CPU等)。 我可以通过某种服务记录我的数据,使该服务成为前台服务,并使用标志PARTIAL_WAKE_LOCK进行电源锁定,从而获得了不错的采样率。
我将代码放在这个要点中https://gist.github.com/julian-ramos/6ee7ad8a74ee4b442530
要点拥有的代码比您需要的更多,但是请注意以下两种方法
@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);
与普通服务不同,以上代码使服务成为OS的优先级。 例如,前台服务的示例是音乐播放器。
使用此代码,即使在自动关闭屏幕后,我也可以获得所需的采样率。
请检查此应用,无论设备型号为https://market.android.com/details?id=singh.pal.ajeet&feature=search_result#?t=W251bGwsMSwxLDEsInNpbmdoLnBhbC5hamVldCJd ,我们都将固定采样频率固定为14-15,以向开发人员发送任何帮助邮件。 virtuoid@gmail.com
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.