我收到后试穿通知点击。
我能够拖动使用辅助服务的通知抽屉。
对于点击我使用的通知accessibilityEvent.getSource()
和accessibilityNodeInfo.performAction(AccessibilityNodeInfo.ACTION_CLICK);
我的代码:
public class MyAccessibilityService extends AccessibilityService {
/**
* On receiving the AccessibilityEvent performs the Actions
*
* @param event
*/
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
Log.i(TAG, "Get the Accessibility Event");
if (event.getEventType() == AccessibilityEvent.TYPE_TOUCH_INTERACTION_END) {
handleTypeTouchInteractionEndEvents(event);
}
if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
handleTypeWindowStateChangedEvents(event);
}
}
@Override
public void onServiceConnected() {
AccessibilityServiceInfo accessibilityServiceInfo = new AccessibilityServiceInfo();
accessibilityServiceInfo.eventTypes = AccessibilityEvent.TYPE_TOUCH_INTERACTION_END | AccessibilityEvent.TYPE_VIEW_CLICKED |
AccessibilityEvent.TYPE_VIEW_FOCUSED | AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED | AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
accessibilityServiceInfo.feedbackType = AccessibilityServiceInfo.CAPABILITY_CAN_PERFORM_GESTURES;
accessibilityServiceInfo.flags = AccessibilityServiceInfo.DEFAULT | AccessibilityServiceInfo.FLAG_RETRIEVE_INTERACTIVE_WINDOWS;
accessibilityServiceInfo.notificationTimeout = NOTIFICATION_TIME_OUT;
this.setServiceInfo(accessibilityServiceInfo);
}
@Override
public void onInterrupt() {
//Do Nothing
}
/**
* Performs the action for TYPE_TOUCH_INTERACTION_END events
*
* @param accessibilityEvent
*/
private void handleTypeTouchInteractionEndEvents(AccessibilityEvent accessibilityEvent) {
switch (accessibilityEvent.getAction()) {
case EXPAND_NOTIFICATIONS_DRAWER:
Log.i(TAG, "perfroming expand notification bar"); performGlobalAction(AccessibilityService.GLOBAL_ACTION_NOTIFICATIONS);
break;
default:
Log.i(TAG, "Event type not defined");
}
}
private void handleTypeWindowStateChangedEvents(AccessibilityEvent accessibilityEvent) {
switch (accessibilityEvent.getAction()) {
case ACTION_CLICK:
Log.i(TAG, "Performing click Action");
findNotificationIconAndClick("com.my.app:id/notification_icon", accessibilityEvent);
Log.i(TAG, "Click Action is successfull");
default:
Log.i(TAG, "Event type not defined");
}
}
public void findNotificationIconAndClick(String id, AccessibilityEvent accessibilityEvent) {
AccessibilityNodeInfo accessibilityNodeInfo = accessibilityEvent.getSource();
List<AccessibilityNodeInfo> nodeInfoList = accessibilityNodeInfo.findAccessibilityNodeInfosByViewId(id);
if (nodeInfoList != null && !nodeInfoList.isEmpty()) {
for (AccessibilityNodeInfo nodeInfo : nodeInfoList) {
if (nodeInfo != null) {
performClick(nodeInfo);
break;
}
}
}
}
}
我是新来使用辅助服务。 谁能告诉我,如果有任何错误,从我的身边,或者如果它是不可能的点击使用无障碍服务的通知? 有没有不使用辅助服务,点击通知任何其他的可能性?