When playing twitter video in android web view it shows the message 'by playing this video you agree to the Twitter use of cookies' and video is not played after that.
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
} else
CookieManager.getInstance().setAcceptCookie(true);
}
webView.getSettings().setJavaScriptEnabled(true);
webView.setBackgroundColor(Color.parseColor("#ffffff"));
webView.loadDataWithBaseURL("file:///android_asset/", htmlTemplate, "text/html", "UTF-8", "");
JavaScript is disabled in a WebView by default.
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
UPDATED:
Use TweetView for Native Videos
Launching native video support for Twitter Kit
Call loadDataWithBaseURL instead of loadData, like this:
loadDataWithBaseURL("https://mywebsite.com", mContent, "text/html", "UTF-8", null);
Related
i want to load url for webview from my json string. but i don't understanding what i need to do for that. i'm trying to load url using getIntent().getExtras().getString("anime_img"); but it's not working. how i can do that? i have json data for the url. here i want to load this image url in webview to open Webview Client.
JSON Data:
image: "https://website.com/library/2019/11/03/1572813810_6.jpg"
my code is:
mainWebView = (WebView)findViewById(R.id.webview);
mainWebView.setWebViewClient(new myWebclient());
mainWebView.loadUrl(getIntent().getExtras().getString("anime_img"));
WebSettings webSettings = mainWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mainWebView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
webSettings.setEnableSmoothTransition(true);
// Recieve data
String webview = getIntent().getExtras().getString("anime_img");
TextView tv_name = findViewById(R.id.aa_anime_name);
// setting values to each view
tv_name.setText(webview);
how i can load the webview url from my json data?
What do you send to in anime_img key? Is the " https://website.com/library/2019/11/03/1572813810_6.jpg "data returning?
So why do you show it in webview? You can display it using libraries such as Glide, Picasso in Imageview. Show this libraries. Glide , Picasso
If you say, I'll show it on webview.
// Recieve data
String webviewUrl = getIntent().getExtras().getString("anime_img");
WebSettings webSettings = mainWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mainWebView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
webSettings.setEnableSmoothTransition(true);
mainWebView = (WebView)findViewById(R.id.webview);
mainWebView.setWebViewClient(webSettings);
mainWebView.loadUrl(webviewUrl);
You can'll try this.
after adding this code my problems has been solved :)
String webviewUrl = getIntent().getExtras().getString("anime_img");
mainWebView = (WebView)findViewById(R.id.webview);
mainWebView.setWebViewClient(new myWebclient());
mainWebView.loadUrl(webviewUrl);
WebSettings webSettings = mainWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mainWebView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
webSettings.setEnableSmoothTransition(true);
special thanks to fevziomurtekin
In one of the screens in my app, I load HTML string into a WebView, but for some reason, the WebView isn't able to load videos in divs, the video container shows error:
This video file cannot be played: error code 102003
This is an example of the HTML that is being loaded, and which the video in it fails to laod:
<html dir="rtl" lang=""><body><meta itemprop="thumbnailUrl" content="https://cdn.jwplayer.com/v2/media/8K9oJcsX/poster.jpg?width=720"/><meta itemprop="contentUrl" content="https://cdn.jwplayer.com/videos/8K9oJcsX-khorc1ya.mp4"/><div style="position:relative; overflow:hidden;"><script src="https://cdn.jwplayer.com/players/8K9oJcsX-4mQgHT7J.js"></script></div></div> <p>تابعي نصائح وأفكار دليل مطبخ سيدتي التي ستساعدك في الحصول على مائدة رمضانية فاخرة ومميزة حتى في أيام الحجر المنزلي.</p></body></html>
I have enabled javascript, added hardwareAcclerated=true added a chrome client and all the other things suggested on other questions.
val settings = webview.settings
settings.domStorageEnabled = true
settings.javaScriptEnabled = true
settings.pluginState = WebSettings.PluginState.ON
webview.webChromeClient = WebChromeClient()
webview.webViewClient = WebViewClient()
settings.setDomStorageEnabled(true);
settings.setAppCacheEnabled(true);
settings.setAppCachePath(getApplicationContext().getFilesDir().getAbsolutePath() + "/cache");
settings.setDatabaseEnabled(true);
settings.setDatabasePath(getApplicationContext().getFilesDir().getAbsolutePath() + "/databases");
settings.allowFileAccess = true
val formattedHtml = "<html dir=\"rtl\" lang=\"\"><body>" + tip.description + "</body></html>"
webview.loadDataWithBaseURL("", formattedHtml, "text/html", "UTF-8", "")
Just tried your video url in my webview and it worked. Here are my settings:
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setMediaPlaybackRequiresUserGesture(false);
So I would guess you have to set setMediaPlaybackRequiresUserGesture to false.
The problem was that the base URL was missing, which is making JWPlayer (the video host) throw an error.
The correct way to do it is to add local android_asset base URL
tipInformation.loadDataWithBaseURL("file:///android_asset/", s, "text/html", "UTF-8", null)
In my recyclerview I am loading webviews as items.
The Item webview may be twitter content, instagram or facebook.
my problem is that the facebook content is not loading in webview.
The html content and my binding part are given below
<iframe style="width:100%;height: 80vh;" allowfullscreen="true" allowtransparency="true" frameborder="0" height="316" scrolling="no" src="https://www.facebook.com/plugins/video.php?href=https%3A%2F%2Fwww.facebook.com%2Fnarendramodi%2Fvideos%2F10159805167945165%2F&show_text=0&width=560" style="border:none;overflow:hidden" width="560"></iframe>
webView =(WebView)itemView.findViewById(R.id.web_view);
WebSettings settings = webView.getSettings();
settings.setDefaultTextEncodingName("utf-8");
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
webView.setFocusable(false);
webView.setClickable(true);
settings.setDomStorageEnabled(true);
settings.setJavaScriptEnabled(true);
settings.setAllowContentAccess(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setLoadsImagesAutomatically(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
} else {
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
webView.loadDataWithBaseURL(null, myHtmlString, "text/html", "UTF-8", null);
I have the code for playing YouTube in WebView on Android.
It works well on new phones (Android 4.4, 5.1, 6, 7 OS) but when I tried it on Android 4.0.3 it opens the YouTube frame with controls and after clicking on button play in the midle the gray background is shown all the time.
The code:
private void initializeWebView() {
WebView webView = (WebView) findViewById(R.id.webView);
//webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
webView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
webView.setBackgroundColor(getResources().getColor(R.color.semi_transparent_black_20percentage));
webView.getSettings().setBuiltInZoomControls(true);
//webView.getSettings().setDisplayZoomControls(false);
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
WebSettings webSetting = webView.getSettings();
webSetting.setJavaScriptEnabled(true);
webSetting.setDisplayZoomControls(false);
//webSetting.setLoadWithOverviewMode(true);
//webSetting.setUseWideViewPort(true);
int screenWidth = getWindowManager().getDefaultDisplay().getWidth();
webView.setLayoutParams(new RelativeLayout.LayoutParams( screenWidth / 2, LayoutParams.MATCH_PARENT));
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webSetting.setJavaScriptEnabled(true);
webSetting.setBuiltInZoomControls(true);
webSetting.setAllowContentAccess(true);
webSetting.setEnableSmoothTransition(true);
webSetting.setLoadsImagesAutomatically(true);
webSetting.setLoadWithOverviewMode(true);
webSetting.setSupportZoom(false);
webSetting.setUseWideViewPort(true);
webSetting.setAppCacheEnabled(true);
webSetting.setSupportMultipleWindows(true);
webView.setVisibility(View.VISIBLE);
}
public void loadPageIntoWebView(String htmlFilename){
AssetManager mgr = getBaseContext().getAssets();
try {
String htmlContentInStringFormat = "";
WebView webView = (WebView) findViewById(R.id.webView);
String frameVideo = "<body>Video From YouTube<br><iframe width=\"420\" height=\"315\" src=\"https://www.youtube.com/embed/2a7f29Jvihc?wmode=transparent\" frameborder=\"0\" allowtransparency></iframe></body>";
htmlContentInStringFormat = frameVideo;
webView.loadDataWithBaseURL(null, htmlContentInStringFormat, "text/html", "utf-8", null);
} catch (Exception e) {
e.printStackTrace();
}
}
This code is working well and playing YouTube videos on newer phones (Android OS4.4-7).
What I should change to get it working on Android 4.0.3 as well ?
this is the photo showing the gray background without playing youtubevideo after clicking on the button play inthe middle of the screen:
Solved!
After I added the following line it works on Android 4.0.3 aswell:
webView.setWebChromeClient(new WebChromeClient() {});
It is not mandatory but I added the line before this line:
webView.setWebViewClient(new WebViewClient()
Hope that this solution will help other collegues working with Epson Moverio BT-200 smart glasses etc.
;-)
I try to load the Google Map Url in a WebView with the following code:
String url = "http://maps.google.com";
WebView webview = (WebView) findViewById(R.id.webview);
//webview settings
webview.setPadding(0, 0, 0, 0);
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient());
webview.loadUrl(url);
and it cannot be loaded (blank).
But the other urls (e.g. http://www.google.com) can be loaded without any problem.
Please help !