0

Is there a way to define shouldOverrideUrlLoading so that I can load URL in a specific external app.

I have a web app displayed in webview and I need to load some video files externally in some other video player instead of default android media player.

Here is the current code:

private class MainWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView webview, String url) {
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setDataAndType(Uri.parse(url), "video/mp4");
            startActivity(i);
            return true;
        }
}

Thanks in advance.

Develoger
  • 3,950
  • 2
  • 24
  • 38
  • Probably you need to parse the url, `shouldOverrideUrlLoading()` might be called for whatever urls are loading, like when the webview is loading the other contents of the webpage like images. Write regex that will detect video content urls then, if the urls is matching then start the intent chooser or specific app. – Nikola Despotoski Mar 12 '13 at 12:59
  • I don't see a question ? – njzk2 Mar 12 '13 at 13:00
  • @Nikola Despotoski there is only one type of URLs that are accessed directly by user in my app, since everything else is done in javascript + ajax + json. So there is not need to check type of URL. – Develoger Mar 12 '13 at 13:03
  • Try whats the outcome if you change the MIME type to `*/*`? Or use intent chooser with the same MIME type. – Nikola Despotoski Mar 12 '13 at 13:10

2 Answers2

1

You have to use onShowCustomView instead. Read more here under "HTML5 Video support".

PC.
  • 6,870
  • 5
  • 36
  • 71
  • Can you show me some code examples since I am quite new to android development even if I am experienced web developer.. – Develoger Mar 12 '13 at 12:59
  • This answer loads the video with HTML5 support, within the WebView, he is looking for a way to start another activity that will load the video outside the WebView – Nikola Despotoski Mar 12 '13 at 13:06
  • that answer is just an example for using onShowCustomView. thats what he asked. – PC. Mar 12 '13 at 13:07
  • Well, I have 2 cases 1) video tag - playing some mp4 live stream in it (It works in android 4+) and 2) in android v3 I can't play same stream in video tag. So I want to try loading it in external app. But I need to specify that app since stream doesn't work in android default media player. – Develoger Mar 12 '13 at 13:12
0
    WebView mWebView;
    mWebView = (WebView) findViewById(R.id.webView1);      
    mWebView.setWebViewClient(new GeoWebViewClient());
    mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    mWebView.getSettings().setBuiltInZoomControls(true);
    mWebView.getSettings().setJavaScriptEnabled(true);       
    mWebView.setWebChromeClient(new GeoWebChromeClient()); 
    mWebView.loadUrl("http://.....");

     public class GeoWebViewClient extends WebViewClient {
   @Override    
    public boolean shouldOverrideUrlLoading(WebView view, String url) { 
   view.loadUrl(url);             
    return true;    
    }   
   }

pls check the following code once

NaseerKhan
  • 65
  • 2
  • 10