- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
由于 API 26 SensorDirectChannel 可用于可能更快的采样率。它可以与 MemoryFile 或 HardwareBuffer 一起用作 Buffer。我在尝试创建 channel 时同时收到 IOExceptions。我试过如下:
SensorManager sm = (SensorManager)getSystemService(Service.SENSOR_SERVICE);
MemoryFile memFile = null;
try {
memFile = new MemoryFile("AccMemoryFile", 1040);
} catch (Exception e) {
e.printStackTrace();
}
SensorDirectChannel channel = sm.createDirectChannel(memFile);
我收到以下消息:
02-26 15:15:46.477 10323-10323/de.makos.directchaneltest E/AndroidRuntime: FATAL EXCEPTION: main
Process: de.makos.directchaneltest, PID: 10323
java.lang.RuntimeException: Unable to start activity ComponentInfo{de.makos.directchaneltest/de.makos.directchaneltest.MainActivity}: java.io.UncheckedIOException: java.io.IOException: create MemoryFile direct channel failed -12
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.io.UncheckedIOException: java.io.IOException: create MemoryFile direct channel failed -12
at android.hardware.SystemSensorManager.createDirectChannelImpl(SystemSensorManager.java:587)
at android.hardware.SensorManager.createDirectChannel(SensorManager.java:904)
at de.makos.directchaneltest.MainActivity.onCreate(MainActivity.java:37)
at android.app.Activity.performCreate(Activity.java:7044)
at android.app.Activity.performCreate(Activity.java:7035)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.io.IOException: create MemoryFile direct channel failed -12
at android.hardware.SystemSensorManager.createDirectChannelImpl(SystemSensorManager.java:588)
at android.hardware.SensorManager.createDirectChannel(SensorManager.java:904)
at de.makos.directchaneltest.MainActivity.onCreate(MainActivity.java:37)
at android.app.Activity.performCreate(Activity.java:7044)
at android.app.Activity.performCreate(Activity.java:7035)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
使用 HardwareBuffer 我得到了类似的异常。代码:
HardwareBuffer accHawBuff = HardwareBuffer.create(1040, 1, HardwareBuffer.BLOB, 1, HardwareBuffer.USAGE_SENSOR_DIRECT_DATA);
SensorDirectChannel channel= sm.createDirectChannel(accHawBuff);
异常信息:
02-26 15:27:07.592 10774-10774/de.makos.brakelightdatacollector E/AndroidRuntime: FATAL EXCEPTION: main
Process: de.makos.brakelightdatacollector, PID: 10774
java.lang.RuntimeException: Unable to start activity ComponentInfo{de.makos.brakelightdatacollector/de.makos.brakelightdatacollector.MainActivity}: java.io.UncheckedIOException: java.io.IOException: create HardwareBuffer direct channel failed -12
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.io.UncheckedIOException: java.io.IOException: create HardwareBuffer direct channel failed -12
at android.hardware.SystemSensorManager.createDirectChannelImpl(SystemSensorManager.java:612)
at android.hardware.SensorManager.createDirectChannel(SensorManager.java:927)
at de.makos.brakelightdatacollector.MesseinheitDirectChanel.registerListener(MesseinheitDirectChanel.java:63)
at de.makos.brakelightdatacollector.MainActivity.onCreate(MainActivity.java:64)
at android.app.Activity.performCreate(Activity.java:7044)
at android.app.Activity.performCreate(Activity.java:7035)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.io.IOException: create HardwareBuffer direct channel failed -12
at android.hardware.SystemSensorManager.createDirectChannelImpl(SystemSensorManager.java:613)
at android.hardware.SensorManager.createDirectChannel(SensorManager.java:927)
at de.makos.brakelightdatacollector.MesseinheitDirectChanel.registerListener(MesseinheitDirectChanel.java:63)
at de.makos.brakelightdatacollector.MainActivity.onCreate(MainActivity.java:64)
at android.app.Activity.performCreate(Activity.java:7044)
at android.app.Activity.performCreate(Activity.java:7035)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
由于没有使用直接 channel 的示例或其他文档,我不确定我是否错过了什么。我在运行 Oreo 8.1 (API 27) 的真实和虚拟设备上进行了尝试。我稍微查看了 native 函数,但找不到原因。我也无法弄清楚 -12 是什么意思。
我希望有人能澄清这一点。提前致谢
最佳答案
兄弟,我认为造成这个问题的原因是你的设备不支持SensorDirectChannel。
我最近遇到了一个类似的问题,我无法通过传递一个 MemoryFile 实例来创建 SensorDirectChannel,它的 Logcat 信息与你得到的信息几乎相同,但我可以通过传递一个 HardwareBuffer 实例来完成它,这很奇怪。在检查了一些文档后,我从 this site 找到了原因。 .
项目 7.3.9 说:
Blockquote
If device implementations include direct sensor support, they:
[C-3-1] MUST correctly declare support of direct channel types and direct report rates level through the isDirectChannelTypeSupported and getHighestDirectReportRateLevel API.
[C-3-2] MUST support at least one of the two sensor direct channel types for all sensors that declare support for sensor direct channel
- TYPE_HARDWARE_BUFFER
- TYPE_MEMORY_FILE
- SHOULD support event reporting through sensor direct channel for primary sensor (non-wakeup variant) of the following types:
- TYPE_ACCELEROMETER
- TYPE_ACCELEROMETER_UNCALIBRATED
- TYPE_GYROSCOPE
- TYPE_GYROSCOPE_UNCALIBRATED
- TYPE_MAGNETIC_FIELD
- TYPE_MAGNETIC_FIELD_UNCALIBRATED
因此,很明显,传感器供应商必须让他们的传感器支持 TYPE_HARDWARE_BUFFER SensorDirectChannel 或 TYPE_MEMORY_FILE SensorDirectChannel 或两者,否则您将无法使用它们。
最后,我通过 isDirectChannelTypeSupported 检查了我设备 (Pixel2) 的加速度传感器并得到如下预期结果: resultscreenshot.希望对您有所帮助。
顺便说一句,我的英语不太好。如果让您感到困惑,我们深表歉意。
关于android - 无法创建 SensorDirectChanel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48991333/
由于 API 26 SensorDirectChannel 可用于可能更快的采样率。它可以与 MemoryFile 或 HardwareBuffer 一起用作 Buffer。我在尝试创建 channe
我是一名优秀的程序员,十分优秀!