1

I've and web app which uses Web view to load the HTML content. I'm developing it for Google TV, The web page having an video in it , So my problem is when i click to play an video it opens in another page not in same webview and it happens for Google TV( Logitech ) not for Mobile device.

What is wrong with it.

My code is:

webView = (WebView) findViewById(R.id.webview);


    WebSettings settings = webView.getSettings();
    //settings.setJavaScriptEnabled(true);
    settings.setAllowFileAccess(true);
    if (Build.VERSION.SDK_INT > 7) {
        settings.setPluginState(PluginState.ON);
    } else {
        settings.setPluginsEnabled(true);
    }

    webView.setWebChromeClient(new SimpleWebChromeClient());
    settings.setJavaScriptEnabled(true);
    settings.setUserAgentString("Mozilla/5.0 (X11; Linux armv7l) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.77 Large Screen Safari/534.24 GoogleTV/000000");
    settings.setBuiltInZoomControls(true);
    settings.setSupportZoom(true);
    settings.setPluginsEnabled(true);
    settings.setLoadWithOverviewMode(true);
    settings.setUseWideViewPort(true);
    webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    webView.setScrollbarFadingEnabled(false);

 String fileName = "html_content/test.html";

 webView.loadUrl("file:///android_asset/" + fileName);

The WebChromeClient code is:

 private class SimpleWebChromeClient extends WebChromeClient {

        /* (non-Javadoc)
         * @see android.webkit.WebChromeClient#onShowCustomView(android.view.View, android.webkit.WebChromeClient.CustomViewCallback)
         */
        @Override
        public void onShowCustomView(View view, CustomViewCallback callback) {
                super.onShowCustomView(view, callback);
                //Log.w(RedditTVHDActivity.LOG_PREFIX, "In OnShowCustomView");
        }

}
Rahul Shirphule
  • 989
  • 3
  • 14
  • 36
  • 1
    I just answered this here: http://stackoverflow.com/questions/16910802/play-video-inside-webview – Krispy Jun 05 '13 at 16:02

2 Answers2

0

This is what I use to open the WebView in the same window.

webview.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView w, String url){
            w.loadUrl(url); 
            return false; // then it is not handled by default action
       }
    });
Simley Jo
  • 33
  • 8
  • If still not working try loading the url with: `webview.loadDataWithBaseURL(url, html, "text/html", "utf-8", url);` I don't know the whole context to tell you if it is a better idea or not. – Simley Jo Jun 04 '13 at 13:37
  • Hi loanaLearns, i add the code for WebChromeClient which set to webview webView.setWebChromeClient(new SimpleWebChromeClient()); is this not helpful ? – Rahul Shirphule Jun 04 '13 at 14:23
0

From your activity name I'm assuming that you are trying to get the Reddit TV links to work in your app. Most of these end up being YouTube videos, so the best is to use the native YouTube Android player API. Here are some YouTube samples apps to look at: https://developers.google.com/youtube/android/player/sample-applications

Leon Nicholls
  • 4,623
  • 2
  • 16
  • 17