我正在开发一个应用程序,当WhatsApp调用启动时(在调用者和接收者端都有)或结束时,需要获得某种notification
/ Receiver
。是否可以在我的应用程序中获取Incoming / Outgoing WhatsApp呼叫信息?
将包名称用作" com.whatsapp
",我无法满足我的要求。
有人会建议我该怎么办?或者这可以实际完成吗?如果是,那么请解释如何。
答案 0 :(得分:4)
我尝试了,我能够捕获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,系统可以在" Talkback"辅助功能模式。希望这会有所帮助!!!
答案 1 :(得分:1)
让我们解决问题.... 当您收到针对所需包裹名称的通知时,辅助功能服务将帮助您获得通知。例如" com.whatsapp"。
现在好处是您可以通过一点点努力在Accessibility Service中解析自Android 4.2以来的通知消息。不幸的是,有一个github project正在做你想要的事情,但它目前无法使用。