1

I'm trying to make an app where when a youtube video inside a webview is clicked then a Shared preferences takes only the id of the video but it's not working, what is wrong? I've been trying for days (I'm new to programming can have a lot of mistakes).

    WebView webView = new WebView(InicioActivity.this);
    webView.loadUrl("https://m.youtube.com/");
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            String pattern = "(?<=watch\\?v=|/videos/|embed\\/|youtu.be\\/|\\/v\\/|\\/e\\/|watch\\?v%3D|watch\\?feature=player_embedded&v=|%2Fvideos%2F|embed%\u200C\u200B2F|youtu.be%2F|%2Fv%2F)[^#\\&\\?\\n]*"; 
            Pattern compiledPattern = Pattern.compile(pattern); 
            Matcher matcher = compiledPattern.matcher(webView.getUrl()); 
            //Extracting the youtube id from the link
            if (matcher.find()) {
                yy.edit().putString("link", matcher.group()).commit();
                //Setting the youtube id to a shared preferences
            }
        } });
Walker
  • 11
  • 3

0 Answers0