Question

I have been working on an app which displays all the notifications in the phone's status bar (like a new msg or a missed call). By researching I found out that the only way to do that in android is to create an accessibility service. So I did the same by getting AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED in my accessibility service.
Here is my onServiceConnected() method:

public void onServiceConnected(){
    if (isInit) {
        return;
    }
    AccessibilityServiceInfo info = new AccessibilityServiceInfo();
    info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED;
    info.feedbackType = AccessibilityServiceInfo.FEEDBACK_SPOKEN;
    setServiceInfo(info);
    isInit = true;
}

This is working but not exactly I wish. Its actually showing many notifications which are not there in status bar and are being probably generated by background apps which i don want. Also its not real time. It updates only when I re-open the app and not while the app is open. Furthermore, as soon as I start the service in settings, my phone(galaxy note) starts talking everything. Not sure if it's a bug or some problem in the code.
I can't figure out where exactly the problem is but I think it can be the feedback type. I tried a lot but couldn't find out the meaning of different feedback types for the service anywhere.

FEEDBACK_AUDIBLE
FEEDBACK_HAPTIC
FEEDBACK_AUDIBLE
FEEDBACK_VISUAL
FEEDBACK_GENERIC

Can someone please tell me what does these feedback types imply? And would I get different notifications if I change the feedback type? And if you believe I'm heading in the wrong direction then please guide me to what I can do to solve these problems. Lemme know if I forgot to provide some essential info.

Any kind of help would be really appreciated.

Was it helpful?

Solution

Well I don't have answers to all your questions but I can help you with something. As you mentioned that you want only statusbar notifications and not others like toasts and all. So for that purpose, you can try the following code in your service.

public void onAccessibilityEvent(AccessibilityEvent event) {
    final int eventType = event.getEventType();
    if (eventType == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
        Parcelable parcelable = event.getParcelableData();

        if(parcelable instanceof Notification){
            // statusbar notification
            List<CharSequence> messages = event.getText();
            if (messages.size() > 0) {
                // here you can do whatever you want with the notification.
                //Log.d(tag, "Saved event");
            }
        }
    }
}

Also set a timeout in your onServiceConnected like this:

info.notificationTimeout=100;  

I hope it works for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top