Salman Nazir
Salman Nazir

Reputation: 2837

Android Whatsapp Call Start Broadcast Receiver

I am working on an application that needs to get some sort of notification/ Receiver when the WhatsApp call is being started (Both on the Caller and Receiver end) or ended. Is it possible to get Incoming/Outgoing WhatsApp call information within my application?

I have tried to use Accessibility Service

Using package name as "com.whatsapp", I'm unable to fulfil my requirement. Will anyone suggest me what should I do? Or Can this actually be done? IF yes, Then please explain how.

Upvotes: 7

Views: 6349

Answers (2)

Dinash
Dinash

Reputation: 3047

I tried it and I am able to capture the WhatsApp call button click and call end button click actions. Below is the simple AccessibilityService that I used and it's consistent with the example available on the Android Developers website

public class MyAccessibilityService extends AccessibilityService {

    @Override
    protected void onServiceConnected() {
        AccessibilityServiceInfo info = new AccessibilityServiceInfo();
        // Set the type of events that this service wants to listen to.  Others
        // won't be passed to this service.
        info.eventTypes = AccessibilityEvent.TYPE_VIEW_CLICKED |
                AccessibilityEvent.TYPE_VIEW_FOCUSED;

        // If you only want this service to work with specific applications, set their
        // package names here.  Otherwise, when the service is activated, it will listen
        // to events from all applications.
        info.packageNames = new String[]
                {"com.whatsapp","com.android.calendar"};

        // Set the type of feedback your service will provide.
        info.feedbackType = AccessibilityServiceInfo.FEEDBACK_SPOKEN;

        // Default services are invoked only if no package-specific ones are present
        // for the type of AccessibilityEvent generated.  This service *is*
        // application-specific, so the flag isn't necessary.  If this was a
        // general-purpose service, it would be worth considering setting the
        // DEFAULT flag.

        // info.flags = AccessibilityServiceInfo.DEFAULT;

        info.notificationTimeout = 100;

        this.setServiceInfo(info);
    }

    @Override
    public void onAccessibilityEvent(AccessibilityEvent event) {
        final int eventType = event.getEventType();
        String eventText = null;
        switch(eventType) {
            case AccessibilityEvent.TYPE_VIEW_CLICKED:
                eventText = "Focused: ";
                break;
            case AccessibilityEvent.TYPE_VIEW_FOCUSED:
                eventText = "Focused: ";
                break;
        }

        //eventText = eventText + event.getContentDescription();

        // Do something nifty with this text, like speak the composed string
        // back to the user.
        Toast.makeText(getApplicationContext(),""+eventText +" --- "+event.getContentDescription(),Toast.LENGTH_LONG).show();
    }

    @Override
    public void onInterrupt() {

    }
}

In the above code I have shown a toast message and, for the trick for drawable, we will be providing the contentDescription which could be used by the system while in "Talkback" accessibility mode. Hope this helps!!!

Upvotes: 4

Attiq ur Rehman
Attiq ur Rehman

Reputation: 475

Let's solve the query.... Accessibility Service will help you to get notified that when you will receive the notifications against your required package name. for example "com.whatsapp".

Now good thing is that you can parse the notification message within since Android 4.2 within Accessibility Service by a little effort. Unluckily for you, There was a github project that was exactly doing your desired thing but it is currently unavailable.

Upvotes: 1

Related Questions