如何使用 4.0 以上的辅助功能服务在 android 中获取通知?
为什么onAccessibilityEvent(AccessibilityEvent event)
在 4.0 以上触发通知时不调用 请给出正确的建议
提前致谢
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
final int eventType = event.getEventType();
System.out.println("MyServ.onAccessibilityEvent()");
switch (eventType) {
case AccessibilityEvent.TYPE_VIEW_FOCUSED:
Toast.makeText(getApplicationContext(), "Notification fired",
Toast.LENGTH_LONG).show();
break;
case AccessibilityEvent.TYPE_ANNOUNCEMENT:
Toast.makeText(getApplicationContext(), "Type is Announcement",
Toast.LENGTH_LONG).show();
break;
default:
break;
}
}
在onServiceConnected()
@Override
protected void onServiceConnected() {
super.onServiceConnected();
AccessibilityServiceInfo info = new AccessibilityServiceInfo();
info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED;
info.feedbackType = AccessibilityServiceInfo.FEEDBACK_SPOKEN;
setServiceInfo(info);
}