My app uses a WebView. I need to open a native video player any time a user clicks on a video. I see that sometimes in sites, if you click on a video thumb, it opens a dialog asking you how you want to open it (via web or a video player).

What can I do on the server side or my app so an intent like this will be sent after a click on a video?

Thanks!

有帮助吗?

解决方案

The question got a little sideways at the end, but I'll respond to the base question.

1.) "I need to open a native video player any time a user clicks on a video"

Verify the link is a video, and fire an intent for ACTION_VIEW, Here's an example:

public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (url.endsWith(".mp4")) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(url));
            startActivity(intent);
            return true;
        } 
        else
            view.loadUrl(url);
            return false;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top