如何启动 AccessibilityService?
我正在尝试通过使用来开始我的 AccessibilityService 实现
I'm trying to start my implementation of AccessibilityService by using
Intent mailAccessabilityIntent = new Intent(this, EmailAccessabilityService.class);
startService(mailAccessabilityIntent);
我的问题是 onServiceConnected()
从未被调用过.如何正确启动此服务?
My problem is onServiceConnected()
never been called.
How do i start this service properly?
由于无障碍服务能够探索屏幕内容并与之交互,因此用户必须在设置">无障碍"中明确启用服务.启用服务后,系统会自动启动它并将其绑定到可访问性 API.
Because accessibility services are able to explore and interact with on-screen content, a user has to explicitly enable services in Settings > Accessibility. Once a service is enabled, the system will start it automatically and bind it to the accessibility APIs.
确保在应用程序清单中声明您的服务:
Make sure you declare your service in your application manifest:
<service android:name=".MyAccessibilityService"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
. . .
</service>
您还需要通过覆盖 setServiceInfo(AccessibilityServiceInfo) 或添加元数据属性和 XML 配置文件来为您的服务提供配置.
You'll also need to provide configuration for your service, either by overriding setServiceInfo(AccessibilityServiceInfo) or adding a meta-data attribute and XML config file.
元数据属性进入您的<service><intent-filter> 之后的声明标签,看起来像这样:
The meta-data attribute goes in your <service> declaration after the <intent-filter> tag and looks like this:
<meta-data android:name="android.accessibilityservice"
android:resource="@xml/accessibilityservice" />
您正在引用的 XML 配置(在本例中,accessibilityservice.xml)如下所示:
The XML config that you're referencing (in this case, accessibilityservice.xml) looks like this:
<accessibility-service
android:accessibilityEventTypes="typeViewClicked|typeViewFocused"
android:packageNames="foo.bar, foo.baz"
android:accessibilityFeedbackType="feedbackSpoken"
android:notificationTimeout="100"
android:accessibilityFlags="flagDefault"
android:settingsActivity="foo.bar.TestBackActivity"
android:canRetrieveWindowContent="true"
. . .
/>