简体   繁体   English

Facebook messenger可访问性

[英]Facebook messenger accessibility

I am writing an accessibility app that helps users navigate on android using a mixture of voice controls and controls provided via external aiding tools. 我正在编写一个辅助功能应用程序,帮助用户使用语音控件和通过外部辅助工具提供的控件混合在Android上导航。 It uses MonkeyTalk Java API to do the heavier work. 它使用MonkeyTalk Java API来完成更重的工作。
To help the user about what is happening we use an accessibility service as well, which reads notification so the user can take action faster. 为了帮助用户了解正在发生的事情,我们还使用了辅助功能服务,该服务会读取通知,以便用户可以更快地采取措施。

I've been informed that they get no audio cue when a message arrives on facebook messenger, and checking logs what I see is: 我被告知,当消息到达facebook messenger时,他们没有得到音频提示,并且检查日志我看到的是:

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

and event.getText().size() returns 0 (on AccessibilityEvent event). event.getText().size()返回0(在AccessibilityEvent事件上)。
Right now they have to open the app and get the text read to them, which is 2 voice commands more... 现在他们必须打开应用程序并将文本读取给他们,这是2个语音命令更多...
I get all the other notifications correctly. 我正确地收到了所有其他通知。 I tried looking for documentation from facebook about their stance on accessibility but I found nothing. 我试着从facebook上寻找关于他们对可访问性的立场的文档,但我一无所获。
Is there any way to get the text from their notifications? 有没有办法从他们的通知中获取文本?

You can try this to see if it works with Facebook messenger notifications. 您可以尝试使用它来查看它是否适用于Facebook Messenger通知。 And even if this does work, I would suggest that you wait for a better solution. 即使这确实有效,我建议您等待更好的解决方案。

From API 19 and above, Notification objects carry bundled extras - the inputs passed to Notification.Builder when the Notification was first created. 从上面的API 19和, Notification对象携带捆绑extras -传递给输入Notification.Builder的时Notification首次创建。 So, information such as the title , context , summary etc. can be extracted from this Bundle using keys of form Notification.EXTRAS_XXXX . 因此,可以使用形式Notification.EXTRAS_XXXX密钥从此Bundle提取诸如titlecontextsummary等信息。 The keys can be found here: Link . 密钥可以在这里找到: 链接

In the overriden onAccessibilityEvent(AccessibilityEvent event) method: 在重写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) can be a method from here: Link . extractTextFromNotification(Notification)可以是这里的方法: Link Needless to say that this is a workaround, and will require quite a bit of testing to ensure that it works as required. 毋庸置疑,这是一种解决方法,需要进行相当多的测试才能确保其按要求运行。

You may use getActiveNotifications method of NotificationListenerService to get an array of notifications that are visible to current user. 您可以使用NotificationListenerService getActiveNotifications方法来获取当前用户可见的通知数组。 The result is an StatusBarNotification array, So you can read the PackageName with getPackageName and if it matches with that you are looking for, then get the notification content from that object (with getNotification )... 结果是一个StatusBarNotification数组,因此您可以使用getPackageName读取PackageName,如果它与您要查找的匹配,则从该对象获取通知内容(使用getNotification )...

You can extend NotificationListenerService class and register it as a service: 您可以扩展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>

Also you can implement onNotificationPosted method to get notifications and even cancel notifications with cancelNotification method. 您还可以实现onNotificationPosted方法来获取通知,甚至使用cancelNotification方法取消通知。

An example of using this service: https://github.com/kpbird/NotificationListenerService-Example 使用此服务的示例: https//github.com/kpbird/NotificationListenerService-Example

Note : User must enable notification permission from "Settings > Security > Notification access". 注意 :用户必须从“设置>安全性>通知访问权限”启用通知权限。 You can open that setting with: 您可以使用以下命令打开该设置

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM