【问题标题】:Android Whatsapp Call Start Broadcast ReceiverAndroid Whatsapp 呼叫启动广播接收器
【发布时间】:2016-03-17 20:33:18
【问题描述】:

我正在开发一个应用程序,该应用程序需要在 WhatsApp 呼叫开始(在呼叫者和接收者端)或结束时获得某种 notification/Receiver。是否可以在我的应用程序中获取传入/传出的 WhatsApp 呼叫信息?

我尝试过使用Accessibility Service

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

【问题讨论】:

  • 你确认了什么UI的行为是什么?
  • 我尝试使用辅助功能服务从 Whatsapp 捕获特定文本,但呼叫按钮是可绘制的,而不是文本。这也是一个问题所以我正在寻找是否有任何其他方式可以在whatsapp调用开始和结束时获取信息?
  • 您想知道用户何时点击了whatsapp操作栏中的通话图标吗?

标签: android broadcastreceiver whatsapp


【解决方案1】:

我试过了,我能够捕捉到 whatsapp 呼叫按钮点击和呼叫结束按钮点击动作。下面是我使用的简单 AccessibilityService,它与 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() {

}

}

在上面的代码中,我展示了一个 toast 消息和 drawable 的技巧,我们将提供 contentDescription,系统在“对讲”可访问性模式下可以使用它。希望这有帮助!!!

【讨论】:

  • 嗨 Dinash,当whatapp 呼叫被接收/结束时,它是否也会显示 toast 消息?
  • @iAmLearning 默认情况下,您不会收到用于接收和结束的 toast 消息。但是您可以设法找到“结束”按钮和“参加呼叫”按钮的点击。
【解决方案2】:

让我们解决查询.... 辅助功能服务将帮助您获得通知,即您何时会收到针对所需包名称的通知。例如“com.whatsapp”。

现在的好处是,您可以通过一点点努力在无障碍服务中解析自 Android 4.2 以来的通知消息。不幸的是,有一个 github project 正在做你想要的事情,但它目前不可用。

【讨论】:

  • 您提到的链接已损坏。正如我在问题中提到的那样,我也搞砸了无障碍服务,但不幸的是我无法满足我的要求。因为我想在whatsapp调用开始时在我的应用程序中获得广播/意图/通知或任何类型的标志。
  • 使用 Accessiblity 服务,我无法跟踪 whatsapp 呼叫按钮,因为它上面没有文字,它是可绘制的。这很难捕捉到,我如何跟踪通话结束?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多