gpt4 book ai didi

android - 无法创建 SensorDirectChanel

转载 作者:行者123 更新时间:2023-11-29 14:12:31 26 4
gpt4 key购买 nike

由于 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com