Tuesday, 5 April 2022

How to get youtube video play ID using accessibility service or any other way in android device

This is my code

private String YOUTUBE_FULL_SCREEN_BTN_ID = "com.google.android.youtube:id/fullscreen_button";
    private String YOUTUBE_VIDEO_TITLE_ID = "com.google.android.youtube:id/title";
    private static final String TAG = "YouTubeFilterService";

    @Override
    public void onAccessibilityEvent(AccessibilityEvent event) {
        try {
            Log.d(TAG, "Event Name : " + AccessibilityEvent.eventTypeToString(event.getEventType()));
            if (getRootInActiveWindow().findAccessibilityNodeInfosByViewId(YOUTUBE_FULL_SCREEN_BTN_ID) != null
                    && getRootInActiveWindow().findAccessibilityNodeInfosByViewId(YOUTUBE_FULL_SCREEN_BTN_ID).size() > 0) {
                List<AccessibilityNodeInfo> listOfResIDs = getRootInActiveWindow().findAccessibilityNodeInfosByViewId(YOUTUBE_VIDEO_TITLE_ID);
                Log.d(TAG, "[MyAccessibilityService] inside onAccessibilityEvent() list size : " + listOfResIDs.size());
                if (listOfResIDs != null && listOfResIDs.size() > 0
                        && listOfResIDs.get(0) != null && listOfResIDs.get(0).getText() != null
                        && listOfResIDs.get(0).getText().length() > 0) {
                    listOfResIDs.get(0).getText().toString().split("\\[\\s]+");
                    String[] splittedTitle = Util.splitParts(listOfResIDs.get(0).getText().toString().toLowerCase());
                    List<String> ngramTitle = Util.generateNgramsUpto(listOfResIDs.get(0).getText().toString().toLowerCase(), splittedTitle.length);

                    
                }
            }

        } catch (Exception e) {
            Log.d(TAG, "[MyAccessibilityService] inside onAccessibilityEvent() Exception is :" + e.toString());
        }

    }

using this code i am able to get event when we click on video is play but i want to get that video Video ID but in my code i don't know how to get video ID in given code i am getting

listOfResIDs = getRootInActiveWindow().findAccessibilityNodeInfosByViewId(YOUTUBE_VIDEO_TITLE_ID);

size is zero please help me how to get video id when user will play on device please or any other way to get played video id. i am trying to create parental control child type of APP.



from How to get youtube video play ID using accessibility service or any other way in android device

No comments:

Post a Comment