当前位置:   article > 正文

android辅助功能开关监听,android – onKeyEvent和辅助功能服务

android onkeyevent

我的用户将使用TalkBack或其他一些Accessible Service.我想在我们的应用程序中捕获onKeyEvent事件,但事件将被分派到启用的Accessibility Services.我创建了以下基本辅助功能服务.

public class Accessibility_Service extends AccessibilityService {

private String TAG = Accessibility_Service.class.getSimpleName();

@Override

public boolean onKeyEvent(KeyEvent event) {

int action = event.getAction();

int keyCode = event.getKeyCode();

if (action == KeyEvent.ACTION_UP) {

if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {

Log.d("Hello","KeyUp");

} else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {

Log.d("Hello","KeyDown");

}

return true;

} else {

return super.onKeyEvent(event);

}

}

/**

* Passes information to AccessibilityServiceInfo.

*/

@Override

public void onServiceConnected() {

Log.v(TAG,"on Service Connected");

AccessibilityServiceInfo info = new AccessibilityServiceInfo();

info.packageNames = new String[] { "com.camacc" };

info.eventTypes = AccessibilityEvent.TYPES_ALL_MASK;

info.notificationTimeout = 100;

info.FeedbackType = AccessibilityServiceInfo.FeedBACK_SPOKEN;

setServiceInfo(info);

}// end onServiceConnected

/**

* Called on an interrupt.

*/

@Override

public void onInterrupt() {

Log.v(TAG,"***** onInterrupt");

}// end onInterrupt

@Override

public void onAccessibilityEvent(AccessibilityEvent event) {

// TODO Auto-generated method stub

}

}// end Accessibility_Service class

当我检查logcat时,我没有得到任何回复.是否可以在TalkBack或其他此类辅助功能服务之前使用降低音量和向上事件?

谢谢.

编辑:

添加以下标志仍然没有运气:

info.flags = AccessibilityServiceInfo.FLAG_REQUEST_FILTER_KEY_EVENTS;

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/258625
推荐阅读
相关标签
  

闽ICP备14008679号