Android Whatsapp 通话启动广播接收器

问题描述 投票:0回答:2

我正在开发一个应用程序,当 WhatsApp 通话开始(呼叫方和接收方端)或结束时,需要获得某种

notification
/
Receiver
。是否可以在我的应用程序中获取传入/传出 WhatsApp 通话信息?

我尝试过使用无障碍服务

使用包名称为“

com.whatsapp
”,我无法满足我的要求。 有人会建议我该怎么办吗?或者这实际上可以做到吗?如果是,请解释一下如何。

android broadcastreceiver whatsapp
2个回答
4
投票

我尝试过,我能够捕获 WhatsApp 通话按钮单击和通话结束按钮单击操作。下面是我使用的简单的

AccessibilityService
,它与 Android 开发者网站

上提供的示例一致
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() {

    }
}

在上面的代码中,我显示了一条 toast 消息,对于可绘制的技巧,我们将提供系统在“Talkback”辅助功能模式下可以使用的 contentDescription。希望这有帮助!!!


1
投票

让我们解决这个问题...... 辅助功能服务将帮助您收到有关您何时收到针对您所需的软件包名称的通知的通知。例如“com.whatsapp”。

现在的好处是,从 Android 4.2 开始,您可以通过一点努力在 Accessibility Service 中解析通知消息。对你来说不幸的是,有一个 github 项目 正是在做你想要的事情,但它目前不可用。

© www.soinside.com 2019 - 2024. All rights reserved.