【发布时间】:2014-03-06 12:55:36
【问题描述】:
我需要处理来自加速度传感器和本机库中硬键的事件。 我已经为传感器实现了,效果很好:
looper = ALooper_forThread();
if (looper == NULL)
looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS);
sensorManager = ASensorManager_getInstance();
accSensor = ASensorManager_getDefaultSensor(sensorManager,
ASENSOR_TYPE_ACCELEROMETER);
if (accSensor == NULL)
LOGE("get Default Sensor");
sensorEventQueue = ASensorManager_createEventQueue(sensorManager, looper,
LOOPER_ID, get_sensor_events, NULL);
if (ASensorEventQueue_enableSensor(sensorEventQueue, accSensor) < 0)
LOGE("Enable sensor");
ASensorEventQueue_setEventRate(sensorEventQueue, accSensor,
(1000L / SAMP_PER_SEC) * 1000);
但是对于硬键,我缺少一个 InputQueue 来做同样的事情:
looper = ALooper_forThread();
if (looper == NULL)
looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS);
AInputQueue_attachLooper(inputQueue, looper, LOOPER_ID, get_input_events, NULL);
一种解决方案是在我的情况下直接读取事件文件/dev/input/event3,但我没有正确的权限。我可以更改 init.rc 文件中的权限,但由于事件编号可能会更改,我认为这不是正确的解决方案。我找不到内核驱动程序在创建输入设备时设置权限的方法。
有什么建议吗?
【问题讨论】:
标签: android linux android-ndk