我尝试使用Xamarin Android创建一个全局侦听手势的AccessibilityService。
服务工作并接收手势和事件,但设备停止解释这些事件,似乎任何触摸事件都被丢弃。我已经尝试过所有我能想到的组合,但没有一个能起作用,我必须遗漏一些东西,但不知道是什么......
以下是该服务的代码:
[Service(Enabled = true, Exported = false, Permission = "android.permission.BIND_ACCESSIBILITY_SERVICE"),
IntentFilter(new [] { "android.accessibilityservice.AccessibilityService" }),
MetaData("android.accessibilityservice", Resource = "@xml/serviceconfig")]
public class ActionAccessibilityService : AccessibilityService
{
public override void OnAccessibilityEvent(AccessibilityEvent e)
{
Console.WriteLine("Event: " + e.EventType);
}
public override void OnInterrupt()
{
}
protected override void OnServiceConnected()
{
AccessibilityServiceInfo info = new AccessibilityServiceInfo();
info.EventTypes = EventTypes.GestureDetectionStart | EventTypes.GestureDetectionEnd;
info.Flags = AccessibilityServiceFlags.RequestFilterKeyEvents | AccessibilityServiceFlags.RequestTouchExplorationMode;
info.FeedbackType = Android.AccessibilityServices.FeedbackFlags.Generic;
this.SetServiceInfo(info);
}
protected override bool OnKeyEvent(KeyEvent e)
{
return false;
}
}
以下是servceconfig.xml文件的内容:
<?xml version="1.0" encoding="utf-8" ?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:canRequestFilterKeyEvents="true"
android:canRequestTouchExplorationMode="true"
/>
答案 0 :(得分:0)
通过设置android:canRequestTouchExplorationMode="true"
,您要求设备在您的服务处于活动状态时转到Touch Exploration Mode。