2017-03-05 1 views
1

私はWhatsappのアクセシビリティサービスに取り組んでいます。私はTest Userアクセシビリティサービスの現在のWhatsappウィンドウのタイトルバーの名前を取得するにはどうすればよいですか?

ここでは、その文字列を得ることに興味を持って

:ユーザーが入力ボックスを押すたびに、私は通常のWhatsAppグループの受信者のWhatsAppユーザーまたは名前を持つ現在のタイトルバーを知りたいです私のxmlです:ここでは

<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android" 
    android:accessibilityEventTypes="typeViewClicked|typeViewFocused" 
    android:packageNames="com.whatsapp" 
    android:accessibilityFeedbackType="feedbackSpoken" 
    android:notificationTimeout="100" 
    android:settingsActivity="com.example.android.apis.accessibility.TestBackActivity" 
    android:canRetrieveWindowContent="true" /> 

は私のコードです:

public void onAccessibilityEvent(AccessibilityEvent event) { 
    final int eventType = event.getEventType(); 
    String eventText = null; 
    switch(eventType) { 
     case AccessibilityEvent.TYPE_VIEW_CLICKED: 
      eventText = "Clicked: "; 
      break; 
     case AccessibilityEvent.TYPE_VIEW_FOCUSED: 
      eventText = "Focused: "; 
      break; 
    } 
    eventText = eventText + event.getContentDescription(); 
    Log.d(TAG, "onAccessibilityEvent: " + eventText); 
    if (eventText.toLowerCase().contains("type a message")) { 
     // access the title bar name/string here 
    } 
} 
私は現在のウィンドウまたは親ウィンドウを取得し、そのタイトルをチェックしてみました

、両方がnullのように見える:

AccessibilityNodeInfo currentNode = event.getSource(); 
AccessibilityNodeInfo parentNode = nodeInfo.getParent(); 
AccessibilityWindowInfo currentWindow = currentNode.getWindow(); 
AccessibilityWindowInfo parentWindow = parentNode.getWindow(); 
// currentWindow.getTitle(); 
// parentWindow.getTitle(); 

答えて

0

私はAccessibilityNodeInfosや他のAndroidユーザー補助のAPIを使用して物事に取り組んで支援するためのライブラリを書かれています。ほぼ完了しました。文書化されたニーズがあります。しかし、このライブラリを使用すると、次のようになります。

メインサービス(ルートアクセシビリティノードにアクセスできるようにする)の中で、このようなことをしてください。

A11yNodeInfo nodeInfo = A11yNodeInfo.wrap(getRootInActiveWindow()); 

A11yNodeInfo result = nodeInfo.visit(new A11yNodeInfo.OnVisitListener() { 
    @Override 
    public boolean onVisit(A11yNodeInfo nodeInfo) { 
     A11yNodeInfoMatcher matcher = new A11yNodeInfoMatcher(); 
     //Add properties to the matcher as needed. I'm just guessing here! 

     return matcher.matches(nodeInfo); 
    } 
}); 

あなたは、その要素のアクセシビリティプロパティを探索したい場合、あなたはまた、単に全体のアクセシビリティツリーをプリントアウトすることができます:

Log.d("Tag", A11yNodeInfo.wrap(getRootInActiveWindow).toViewHeirarchy()); 

https://github.com/chriscm2006/Android-Accessibility-Utilities

+0

私はあなたがあなたのライブラリにリンクするのを忘れたと思います – avi

関連する問題