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

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

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

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

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>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5490171.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-12
下一篇 2022-12-12

发表评论

登录后才能评论

评论列表(0条)

保存