如何启动 AccessibilityService? [英] How to start AccessibilityService?

查看:92
本文介绍了如何启动 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"
    . . .
/>

http://developer.android.com 上有关于您可以使用哪些标签的更多信息/reference/android/R.styleable.html#AccessibilityService

这篇关于如何启动 AccessibilityService?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆