【问题标题】:Using AInputQueue_attachLooper() in a native library在本机库中使用 AInputQueue_attachLooper()
【发布时间】: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


    【解决方案1】:

    在本机活动中,您可能希望实现 onInputQueueCreated 回调:

    static void OnInputQueueCreated (ANativeActivity* activity, AInputQueue* queue)
    

    queue 参数将保存指向您要查找的输入队列的指针。

    【讨论】:

      猜你喜欢
      • 2014-03-18
      • 1970-01-01
      • 1970-01-01
      • 2013-03-23
      • 2017-07-06
      • 2011-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多