不幸的是通过其他的答案,延迟(或采样率)为提示你设置是只然而,对于你的应用程序所要求的最低限度的建议(对于系统),这可以根据运行的其他应用程序或进入省电模式的设备(关闭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();
.....}
上面的代码防止OS转关闭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);
与普通服务不同,上述代码使服务成为操作系统的优先级。例如,前台服务的例子是音乐播放器。
使用此代码,即使在手表自动关闭屏幕后,我也能够获得所需的采样率。
我已经尝试了华硕变压器平板电脑上的代码,我有同样的问题。所有传感器延迟使用50赫兹的频率。我也会寻找答案。 – vgonisanz 2012-02-20 10:02:54
您可以尝试使用仿真器的各种配置,以确定它是依赖于操作系统还是依赖于设备。我敢打赌,价值取决于你的硬件,不能改变...另外,阅读此:http://stackoverflow.com/questions/4224223/android-how-to-increase-accelerometer-sampling-rate – 2012-02-28 12:32:19
谢谢,我会尝试与模拟器! – 2012-02-28 14:37:38