栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

以编程方式使用辅助功能阅读通知栏标题和消息

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

以编程方式使用辅助功能阅读通知栏标题和消息

试试看,下面的代码对我有用-

Notification notification = (Notification) event.getParcelableData();RemoteViews views = notification.contentView;Class secretClass = views.getClass();try {    Map<Integer, String> text = new HashMap<Integer, String>();    Field outerFields[] = secretClass.getDeclaredFields();    for (int i = 0; i < outerFields.length; i++) {        if (!outerFields[i].getName().equals("mActions")) continue;        outerFields[i].setAccessible(true);        ArrayList<Object> actions = (ArrayList<Object>) outerFields[i]     .get(views);        for (Object action : actions) { Field innerFields[] = action.getClass().getDeclaredFields(); Object value = null; Integer type = null; Integer viewId = null; for (Field field : innerFields) {     field.setAccessible(true);     if (field.getName().equals("value")) {         value = field.get(action);     } else if (field.getName().equals("type")) {         type = field.getInt(action);     } else if (field.getName().equals("viewId")) {         viewId = field.getInt(action);     } } if (type == 9 || type == 10) {     text.put(viewId, value.toString()); }        }        System.out.println("title is: " + text.get(16908310));        System.out.println("info is: " + text.get(16909082));        System.out.println("text is: " + text.get(16908358));    }} catch (Exception e) {    e.printStackTrace();}

希望对您有帮助。

已编辑

在res文件夹中创建一个名为xml的文件夹-在其中创建一个名为“ accessibilityservice”的xml并粘贴以下代码-

<?xml version="1.0" encoding="utf-8"?>  <accessibility-service  xmlns:android="http://schemas.android.com/apk/res/android" android:accessibilityEventTypes="typeNotificationStateChanged" android:accessibilityFeedbackType="feedbackSpoken" android:notificationTimeout="100" />

并在清单中将您的服务标签更新为以下代码-

<service        android:name=".YourServiceClassName"        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/accessibilityservice" />   </service>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/498050.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号