赞
踩
我的用户将使用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;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。