Android可访问性服务未在Oreo中接收通知

时间:2018-09-21 09:54:50

标签: android accessibility accessibilityservice

我已在我的应用程序中添加了android可访问性,并且它与preeo设备兼容,但在oreo中,我无法收到该应用程序的第二次通知。

我只能收到该应用的第一条通知,而该应用无法收到第二条通知。如果我要从通知托盘清除通知,则可以接收第一个通知,而第二个以后未收到。

例如

    从whatsapp收到的
  1. notification1,服务可以读取
  2. 从whatsapp收到的通知2,服务无法读取
  3. 从Gmail收到
  4. notification3,服务可以读取
  5. 从Gmail收到通知4,服务无法读取
  6. 从whatsapp收到的通知5,服务无法读取

简而言之,第二个以后的通知可访问性会在应用程序的oreo中被忽略。

我的辅助功能代码

    public class NotificationService extends AccessibilityService {

    @Override
    public void onAccessibilityEvent(AccessibilityEvent evt) {
     Toast.makeText(this, "Got event from " + evt.getPackageName(), 
    Toast.LENGTH_SHORT)
            .show();
      }

      @Override
  public void onInterrupt() { }
}

我的清单文件:

<application>
    <activity
        android:name=".MyActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <service android:name=".NotificationService" android:enabled="true" 
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE" >
        <meta-data
            android:name="android.accessibilityservice"
            android:resource="@xml/accessibility_service_config" />
        <intent-filter>
            <action android:name="android.accessibilityservice.AccessibilityService" />
        </intent-filter>
    </service>
</application>

1 个答案:

答案 0 :(得分:0)

可访问性服务可能会在不通知用户的情况下停止,这是一个已知问题。请参考以下代码,以检查服务是否仍在运行。

#!/usr/bin/env python3
# *-* coding: utf-8 *-*
from oscrypto import asymmetric
from endesive import pdf

def main():
    dct = {
        b'sigflags': 3,
        b'contact': b'me@email.com',
        b'location': b'City',
        b'signingdate': b'20180731082642+02\'00\'',
        b'reason': b'Some descriptive message',
    }
    p12 = asymmetric.load_pkcs12(
        open('demo2_user1.p12', 'rb').read(),
        '1234'
    )
    datau = open('pdf.pdf', 'rb').read()
    datas = pdf.cms.sign(datau, dct, p12[0], p12[1], [], 'sha256')
    with open('pdf-signed-cms.pdf', 'wb') as fp:
        fp.write(datau)
        fp.write(datas)

main()

尝试在服务中使用此方法,以免您一次又一次错过通知。希望它会有所帮助。如果有帮助,请接受答案。 谢谢。

相关问题