Home > Mobile >  About barrier-free service simulation click (gestures gestureDescription) abnormal problems
About barrier-free service simulation click (gestures gestureDescription) abnormal problems

Time:10-23

Theme: trying to implement the APP in the background automatically click on any position of the screen function,
, according to online ways to try to use the simulated gestures gestureDescription AccessbilityService (click) only tried, but call abnormal gestures, always go in the callback GestureResultCallback onCancel, rather than the onComplete, don't know why, look from the surface and no trigger I want click effect,

The key code is as follows:
 
Fun click (x: Int, y: Int) {
If (Build) VERSION) SDK_INT & lt; Build. VERSION_CODES. N) return
Val path=path ()
Path. MoveTo (x.t oFloat (), y.t oFloat ())
Val builder=GestureDescription. Builder ()
Val gestureDescription=builder
AddStroke (GestureDescription. StrokeDescription (path, 50, 200))
The build ()
Val result=dispatchGesture (gestureDescription, @ RequiresApi (Build) VERSION_CODES) N)
Object: GestureResultCallback () {
Override fun onCancelled (gestureDescription: gestureDescription? {
Super. OnCancelled (gestureDescription)
Timber. I (" onCancelled: gestureDescription ")
}
Override fun onCompleted (gestureDescription: gestureDescription? {
Super. OnCompleted (gestureDescription)
Timber. I (" onCompleted: gestureDescription ")
}
}, null)
Timber i. (" dispatch gesture: $result, x=$x, y=$y ")
}

CodePudding user response:

Combining the above key code and key log found: dispatchGesture method to return true, but it came to callback GestureResultCallback onCancelled,
Click also didn't see the expected effect,
  • Related