I get tweet blockquote in the description . I create a html document and appened blockquote and twitter script and load that html to webview. All the tweets and videos renders properly. Only problem is, When i click on the video, it shows a black screen. This happening for all twitter videos in kitkat devcies. Works fine in lollypop and above. I know there is a bug in API level 16 and 17 and videos won't play in the webview. But from API level 18, videos in webview must play and all other videos are playing in the webview in these devices. Only the twitter videos are not working. Below is my html content:
<!DOCTYPE html> <head>
<script async src ="http://platform.twitter.com/widgets.js"
charset="utf-8"></script></head> <body><blockquote class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr">Goodbye #Sarbjit.Gratitude to #OmungKumar #Vanita_ok #SandeepSinghOne #RichaChadda_ #kirandeohans #AishwaryaRai CREW pic.twitter.com/1tC4CiCwBN</p>— Randeep Hooda (#RandeepHooda) March 15, 2016</blockquote></body> </html>
This is my webview code:
public static void setupWebview(WebView webView) {
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.setBackgroundColor(Color.parseColor("#ffffff"));
android.webkit.CookieManager.getInstance().setAcceptCookie(true);
}
What might be the issue here. I googled a lot, but couldn't get any solution. Is anyone else also, facing similar issue?
Thanks in Advance
I am facing the same issue.For me it is working on JellyBean(4.1.2) and Lollipop and above,but fails to load on KitKat(API 19). I was checking the logs from the webview by overriding onConsoleMessage method of WebChromeClient and noticed that I am getting the following error after it tries to load the video resource:
Uncaught InvalidStateError: An attempt was made to use an object that
is not, or is no longer, usable.
Check your logs and try to debug what step is failing when trying to render the video.
Related
I have an Android page that features a WebView. I initially generate some HTML and load it into the webview using some code that looks like:
String ASSET_DIR = "file:///android_asset/subdir/";
webview.loadDataWithBaseURL(ASSET_DIR, html, "text/html", "UTF-8", null);
In the onPageFinished callback to my WebViewClient, I want to scroll the view to an anchor in the generated html. In that callback, I call
webview.loadUrl(ASSET_DIR + "#" + myAnchor);
On older versions of WebView (44), this works fine, but on newer versions (70), I get the error:
The webpage at file:///android_asset/subdir/#myAnchor could not be loaded because: net::ERR_FILE_NOT_FOUND
I've tried adding permissions to webview.getSettings(), but without success. How do I fix this?
Note: I'd like to avoid using Javascript to solve this issue. I tried a solution with findElementById.scrollIntoView, but it scrolls off the page on newer WebView versions.
I want to use two html in a single webpage so i choose to implement frameset in html. it works fine in all android version except android4.0. If i html file in default browser its working fine but in webview only one frame is loaded not the other ie first frame is override by second frame so it looks only second frame is loading.
here is my code for loading html in webview..
WebView web=new WebView(this);
String url="<html><frameset cols=\"25%,25%\" FRAMEBORDER=NO FRAMESPACING=0 BORDER=0><frame src=\"file:///android_asset/preview.html"
+"\" /><frame src=\"file:///android_asset/preview.html\" /> </frameset></html>";
web.loadDataWithBaseURL("file:/"+baseurl+"/",url, "text/html", "utf-8","");
i dont know why its not supporting in android4.0 whether android webview is not accepting frame in 4.0 or not? If anyone knows please help me..
I have a webview in my application which upon launch displays an html page. The page has a hyperlink which on click is supposed to display a video.
When i run the application and click on the video hyperlink link , nothing happens. But if i load the same page in android browser, then it launches a default video player and everything works fine.
I debugged it furthers by putting a log statement in shouldOverrideUrlLoading method and noticed that, when the hyperlink is clicked it gets redirected to another link and then to another link (final video streaming url).
My question is : why would the link work perfectly in default android browser and not through a webview.
Thanks
What is happening is when you click the hyperlink, that link probably has some popups inside of it. You need to define the onCreateWindow function in your webview's WebChromeClient. This handles how calls to open new windows or popups are handled.
public boolean onCreateWindow (WebView view, boolean dialog, boolean userGesture, Message resultMsg) {
((WebView.WebViewTransport) resultMsg.obj).setWebView(myWebView);
resultMsg.sendToTarget();
return true;
}
After declaring your WebView you should set javascript enabled, then your WebView will work as a browser.
For example:
WebView mwebview = new WebView(this);
setContentView(mwebview);
mwebview.getSettings().setJavaScriptEnabled(true);
or
mwebview.getSettings().setPluginState(PluginState.ON); // this is for newer API's
Basically, do not expect your embedded WebView works the same as Android default Browser. The default Browser is built on the same WebView, but there are lots a customization. (Especially around the no-standard uri, HTML5 stuff)
I followed code from here: WebView and HTML5 <video>, and I put the video link to a video tag, and I got the Video playing in my own version of WebView. The behavior is a little different from the default Browser. Given more time, we could figure that out by looking at its code, but anyways ...
I am suffering from a strange problem in order to implement WebView in android. I am trying to load html5 supported web page in my WebView, but the problem is default zoom controller is not working in WebView.
i tried with the following code.
webview.getSettings().setBuiltInZoomControls(true);
webview.invokeZoomPicker();
Can any body help regarding this.
Add this line also
WebSettings setting = wView.getSettings();
setting.setBuiltInZoomControls(true);
setting.setSupportZoom(true);
if work or not please reply
I am using the following data to display in a WebView. These are the HTML tags along with
the iframe which is referring to a video.
Now the problem is when I click on it, it shows the play button but cannot play the video.
Can I play this video inside WebView or not?
<p></p><P> because of Jon’s pro-growth, business-friendly policies, Utah's economy expanded at more than triple the national rate and was named the best state for business by <EM>Forbes.</em><BR /><BR /><IFRAME height=241 src="http://player.vimeo.com/video/25349114" frameBorder=0 width=425></iframe></p><br />
<P>America needs a dose of the same medicine. Today, our nation has the second highest corporate tax rate in the developed world. We have convoluted and confusing regulations.
<!--break--><!--break--><p></p>
when I try to run this url in the android browser it opens videoview and plays that file perfectly but why not in iframe?
http://player.vimeo.com/video/25349114
The key thing is to enable browser plugins.
// how to enable the webview plugin changed in API 8
if (Build.VERSION.SDK_INT < 8) {
mWebView.getSettings().setPluginsEnabled(true);
} else {
mWebView.getSettings().setPluginState(PluginState.ON);
}
Also worth checking flash player is installed
WebView wv;
wv = (WebView) findViewById(R.id.mywebview);
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setBuiltInZoomControls(true);
wv.getSettings().setPluginsEnabled(true);
Use this code to load your video and also update the flashplayer of your device...