2016-03-07 81 views
6

我正在開發一個應用程序,當WhatsApp呼叫正在啓動時(在呼叫者和接收者端)或結束時,需要獲得某種notification/Receiver。是否可以在我的應用程序中獲取傳入/傳出WhatsApp電話信息?Android Whatsapp呼叫啓動廣播接收器

我曾嘗試使用Accessibility Service

使用包名稱爲「com.whatsapp」,我無法滿足我的要求。 有人會建議我該怎麼辦?或者這可以做到嗎?如果是,那麼請解釋一下。

+0

你有什麼確認關於什麼時候參與所謂的行爲的用戶界面的行爲? – JoxTraex

+0

我曾嘗試使用輔助功能服務從Whatsapp中捕獲特定文本,但通話按鈕是可繪製的,而不是文本。它也是一個問題所以我正在尋找是否有任何其他方式來獲取信息,當whatsapp調用開始和結束時? –

+0

你想知道用戶何時點擊whatsapp操作欄中的通話圖標嗎? – Dinash

回答

1

讓我們解決查詢問題.... 輔助功能服務將幫助您獲得通知,告知您何時會收到針對所需包名稱的通知。例如「com.whatsapp」。

現在好的一點是,您可以通過一些努力來解析自Android 4.2以後的通知消息。不幸的是,有一個github project正在做你想要的東西,但它目前無法使用。

+0

您提到的鏈接已損壞。此外,我已經與無障礙服務雜亂無章,因爲我在我的問題中提到,但不幸的是,我無法得到我的要求。正如我想在Whatsapp調用開始時在我的應用程序中獲得廣播/意圖/通知或任何類型的標誌。 –

+1

使用Accessiblity服務,我無法跟蹤whatsapp調用按鈕,因爲它上面沒有文本,它的drawable。這很難趕上,同樣如何跟蹤通話結束? –

3

我試過了,我能夠捕獲whatsapp調用按鈕單擊並調用結束按鈕單擊操作。下面是我用在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() { 

} 

}

可用簡單AccessibilityService,並沒有更多的不同比的例子在上面的代碼中,我已經表現出了敬酒消息和繪製的伎倆,我們將提供可在系統處於「對講」輔助模式時使用的contentDescription。希望這可以幫助!!!

+0

嗨Dinash,當whatapp電話收到/結束時它是否也顯示敬酒信息? – iAmLearning

+0

@iAmLearning默認情況下,您不會收到接收和結束的Toast消息。但你可以設法找到點擊結束按鈕和出席呼叫按鈕。 – Dinash

+0

好的。感謝Dinash。我會試試這個 – iAmLearning