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

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

的元数据属性的推移在&LT;服务&GT;意图滤光器&gt;的&lt后声明;标记和看起来像这样:

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"
    . . .
/>

有哪个标记可以使用在<一个更多信息href="http://developer.android.com/reference/android/R.styleable.html#AccessibilityService">http://developer.android.com/reference/android/R.styleable.html#AccessibilityService

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

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