【问题标题】:Facebook messenger accessibilityFacebook 信使可访问性
【发布时间】:2014-09-01 08:36:16
【问题描述】:

我正在编写一个辅助功能应用程序,该应用程序通过混合使用语音控件和通过外部辅助工具提供的控件来帮助用户在 Android 上导航。它使用 MonkeyTalk Java API 来完成较重的工作。
为了帮助用户了解正在发生的事情,我们还使用了无障碍服务,它会读取通知,以便用户可以更快地采取行动。

我被告知,当消息到达 facebook Messenger 时,他们没有收到音频提示,检查日志我看到的是:

D/NotificationService(2665): package com.facebook.orcaText: []

并且event.getText().size() 返回 0(在 AccessibilityEvent 事件中)。
现在他们必须打开应用程序并读取文本给他们,这是另外 2 个语音命令...
我正确收到所有其他通知。我尝试从 facebook 查找有关他们对可访问性的立场的文档,但我一无所获。
有没有办法从他们的通知中获取文本?

【问题讨论】:

    标签: android accessibility facebook-messenger android-a11y


    【解决方案1】:

    您可以试试这个,看看它是否适用于 Facebook Messenger 通知。即使这确实有效,我建议您等待更好的解决方案。

    从 API 19 及更高版本开始,Notification 对象携带捆绑的 extras - 首次创建 Notification 时传递给 Notification.Builder 的输入。因此,可以使用Notification.EXTRAS_XXXX 形式的键从Bundle 中提取titlecontextsummary 等信息。可以在此处找到密钥:Link

    在被覆盖的onAccessibilityEvent(AccessibilityEvent event) 方法中:

    @Override
    public void onAccessibilityEvent(AccessibilityEvent event) {
        Parcelable data = event.getParcelableData();
    
        if (data != null && data instanceof Notification) {
            Log.i("", "We have a notification to parse");
    
            Notification notification = (Notification) data;
    
            // For API 19 and above, `Notifications` carry an `extras` bundle with them
            // From this bundle, you can extract info such as:
    
            //      `EXTRA_TITLE`     -  as supplied to setContentTitle(CharSequence)
            //      `EXTRA_TEXT `     -  as supplied to setContentText(CharSequence)
            //      `EXTRA_INFO_TEXT` -  as supplied to setContentInfo(CharSequence)
            //      ... more at: http://developer.android.com/reference/android/app/Notification.html
    
            Bundle b = noti.extras;
            Log.i("Notification", "Title: " + b.get(Notification.EXTRA_TITLE));
            Log.i("Notification", "Text: " + b.get(Notification.EXTRA_TEXT));
            Log.i("Notification", "Info Text: " + b.get(Notification.EXTRA_INFO_TEXT));
    
            /////////////////////////////////////////////////////////////////
    
            // For API 18 and under:
    
            // Pass `notification` to a method that parses a Notification object - See link below
    
            List<String> notificationText = extractTextFromNotification(notification);
            ....
            ....
        }
    }
    

    extractTextFromNotification(Notification) 可以是这里的方法:Link。不用说,这是一种解决方法,需要进行大量测试以确保它按要求工作。

    【讨论】:

    • 现在我们用的是api19+,所以真的没问题。未来我们会支持老款手机,也许我会使用inflate view技巧,我有点喜欢!
    • 额外的字段被证明是完美的!我现在也将它用于其他通知消息。谢谢!
    • @sokie I am using it now for the rest of the notification messages as well. 太棒了!没想到会推荐你这样做。
    • 我还在谈论 api 19+ 强硬。
    【解决方案2】:

    您可以使用NotificationListenerServicegetActiveNotifications 方法来获取当前用户可见的通知数组。 结果是一个StatusBarNotification 数组,因此您可以使用getPackageName 读取PackageName,如果它与您正在寻找的匹配,则从该对象获取通知内容(使用getNotification)...

    您可以扩展NotificationListenerService 类并将其注册为服务:

    <service android:name=".NotificationListener"
          android:label="@string/service_name"
          android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
     <intent-filter>
         <action android:name="android.service.notification.NotificationListenerService" />
     </intent-filter>
    </service>
    

    您还可以实现onNotificationPosted 方法来获取通知,甚至可以使用cancelNotification 方法取消通知。

    使用此服务的示例: https://github.com/kpbird/NotificationListenerService-Example

    注意: 用户必须从“设置 > 安全 > 通知访问”中启用通知权限。 您可以使用以下命令打开该设置:

    Intent intent=new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
    startActivity(intent);
    

    【讨论】:

    • 对于 facebook messenger,这仍然为空。
    • 你用 facebook messenger 试过这个代码了吗?我访问任何其他通知都没有问题,唯一返回空的通知是 facebook messenger。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-24
    • 2012-12-28
    • 2015-07-01
    • 2014-03-19
    • 1970-01-01
    相关资源
    最近更新 更多