1

我正在构建一个应用程序来监听通知,然后使用accessibilityservice 将其显示到日历上,但是每当我收到通知时(我正在使用电子邮件进行测试,因为我可以不断地向自己发送邮件)onaccessibilityservice 永远不会被调用,我提到到这里的一些答案,但他们都指向 JellyBean,我认为这不是我正在寻找的情况

在我的 AccessibilityListener.class

    @Override
        public void onAccessibilityEvent(AccessibilityEvent event) {
            final int eventType = event.getEventType();
            NotificationInfo info = new NotificationInfo();

            Toast.makeText(getApplicationContext(), "Received event", 1000);

            Log.d("TAG","onaccessibility event running");

            if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED)
            {   
                    info.packageName = (String) event.getPackageName();
                    info.eventTime = event.getEventTime();
                    info.eventText = event.getText().toString();
                    sendEvent(info);            
            }
        }

在我的 Android.manifest

<service 
            android:enabled="true" 
            android:name=".AccessibilityListener"
            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>

在我的 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="feedbackAllMask"
    android:notificationTimeout="100" />
4

0 回答 0