残念ながら、他の回答で示唆されているように、設定した遅延 (またはサンプリング レート) は、アプリケーションが必要とする最小値の (システムに対する) 提案にすぎませんが、これは、実行中の他のアプリケーションやデバイスが省電力状態になることによって大幅に変化する可能性があります。モード(CPUをオフにするなど)。ある程度良いサンプリング レートを得ることができた 1 つの方法は、サービスからデータを記録し、サービスをフォアグラウンド サービスにして、フラグ PARTIAL_WAKE_LOCK で電源ロックを設定することでした。
この要点にコードを入れました
https://gist.github.com/julian-ramos/6ee7ad8a74ee4b442530
その要点には必要以上のコードがありますが、次の 2 つのメソッドに注意してください
@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);
上記のコードは、通常のサービスとは異なり、サービスを OS の優先事項にします。フォアグラウンド サービスの例としては、音楽プレーヤーなどがあります。
このコードを使用すると、時計が自動的に画面をオフにした後でも、必要なサンプリング レートを取得できました。