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 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页