Aliens 2017-08-15 04:11 采纳率: 100%
浏览 2292
已采纳

辅助功能服务类AccessibilityService的xml配置文件编译报错

新手,写了一个可以自动回复手机qq消息的服务,编译时有一个错误:No resource found that matches the given name (at 'resource' with value '@xml/Accessibility_service_config')

代码编写过程如下:
1. 编写自己的AccessibilityService类,重写onServiceConnected()方法、onAccessibilityEvent()方法和onInterrupt()方法
2. 新建配置文件/res/xml/accessibility_service_config.xml

 <?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
            android:accessibilityEventTypes="typeNotificationStateChanged|typeWindowStateChanged|typeWindowContentChanged|typeWindowsChanged" 
            android:accessibilityFeedbackType="feedbackGeneric"
            android:accessibilityFlags="flagDefault"
            android:canRetrieveWindowContent="true"
            android:description="@string/description"
            android:notificationTimeout="100"
            android:packageNames="com.tencent.mobileqq" />

3.在AndroidManifest.xml中配置该服务信息,并增加meta-data标签指定xml文件:

<service
        android:name=".QQMsgAccessibilityService"
        android:enabled="true"
        android:exported="true"
        android:label="@string/label"
        android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
        <intent-filter>
                        <action android:name="android.accessibilityservice.AccessibilityService" />
        </intent-filter>
        <meta-data android:name="android.accessibilityservice" android:resource="@xml/Accessibility_service_config"></meta-data>
</service> 

不知道什么地方出错了,根据错误提示好像是找不到资源文件,但是根据网上找的资料,accessibility_service_config.xml应该就放在res/xml/下面。android编译版本是6.0,应该是支持以xml文件的方式配置AccessibilityService的。

  • 写回答

2条回答 默认 最新

  • Aliens 2017-08-15 16:02
    关注

    问题找到了,"@xml/Accessibility_service_config中,文件名Accessibility_service_config应该全部是小写,改成@xml/accessibility_service_config即可。
    其实刚开始我就写的小写,但是因为编译产生了另一个错误,大概是typeNotificationStateChanged|typeWindowStateChanged|typeWindowContentChanged|typeWindowsChanged参数不能是string类型,我想了好多办法都不行,参考String.xml和AndroidManifest.xml等文件都是首字母大写啊,于是就改成大写了,于是就不认了,但是我没发现错误代码变了,以为和改之前是一个错误。现在改成小写后,同时还需将typeNotificationStateChanged|typeWindowStateChanged|typeWindowContentChanged|typeWindowsChanged改成typeAllMask就可以编译通过了。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序