7

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.

Piyush
  • 1,744
  • 1
  • 15
  • 28
Salman Nazir
  • 2,759
  • 2
  • 28
  • 42
  • What have you confirmed about the behavior of the UI of whats up when engaging in the so-called behaviors? – JoxTraex Mar 10 '16 at 07:18
  • I have tried using Accessibility Service to catch specific Text from Whatsapp , But the Call button is a drawable , not the text. Its also a problem So i was searching if any other way to get information when the whatsapp call starts and when it ends? – Salman Nazir Mar 10 '16 at 07:22
  • Do you want to know when the user clicks on the call icon in whatsapp actionbar? – Dinash Mar 17 '16 at 12:19

2 Answers2

4

I tried it and I am able to get capture the whatsapp call button click and call end button click actions. Below is the simple AccessibilityService that I used and it no more different than the example available in 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 showed a toast message and 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!!!

Dinash
  • 3,027
  • 4
  • 32
  • 45
  • Hi Dinash, does it also show the toast message when whatapp call is received/ended ? – iAmLearning Oct 06 '17 at 04:26
  • @iAmLearning by default, you will not get the toast message for receive and end. But you can manage to find the click of End button and Attend Call buttons. – Dinash Oct 06 '17 at 07:17
1

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.

Attiq ur Rehman
  • 475
  • 1
  • 6
  • 21
  • Your mentioned link in broken . Also i have messed with Accessibility Service as i have mentioned in my question but Unfortunately i am unable to get my requirements with it. As i want to get broadcast/Intent/Notification or any sort of Flag in my application when whatsapp call starts. – Salman Nazir Mar 10 '16 at 07:14
  • 1
    Using Accessiblity service , i am unable to track the whatsapp call button as there is no text over it , its drawable. that is hardly to catch and the same how can i track the call end? – Salman Nazir Mar 10 '16 at 08:12