Webview doesnt load image with String Html - android

Im making an app in which i show one wikipedia page, for testing im create a new project.
mvw.getSettings().setJavaScriptEnabled(true);
mvw.getSettings().setLoadsImagesAutomatically(true);
mvw.getSettings().setAllowContentAccess(true);
mvw.getSettings().setDomStorageEnabled(true);
mvw.setWebViewClient(new mostrarEnAplicaion());
String htmlString = "<!DOCTYPE html><html><body style = \"text-align:center\"><img src=\"https://en.wikipedia.org/?curid=52633874#/media/File:Wat_Phra_Mahathat_Woramahawihan,_Nakhon_Si_Thammarat.jpg\" alt=\"pageNo\" height=\"100%\" width=\"100%\"></body></html>";
mvw.loadDataWithBaseURL(null,htmlString,"text/html","UTF-8","about:blank");
If I load the URL directly works fine
mvw.loadUrl("https://en.wikipedia.org/wiki/Santa_Mar%C3%ADa_del_Naranco");
I have the permission.INTERNET on the Manifest but doesnt work, anyone know the solution?

After look for a while, I just see that in this line
mvw.loadDataWithBaseURL(null,htmlString,"text/html","UTF-8","about:blank");
I only have to change the null (BaseUrl) for the url of the website in which the images are storage, in this case "https://en.wikipedia.org/"

Related

How can i render html with using geckoview?

I wanted to download a html file from a website first and edit that website and print that html with geckoview render engine
I know how to fetch a html and parse it but i don't know how to render it with using the renderengine
Geckoview just uses a url of a website
I don't want to use webview because i don't think it's not that good to make my own web browser app
GeckoSession has loadString(String htmlString, String mimeType) method:
GeckoSession geckoSession = ...;// here you start session in your GeckoView
geckoSession.loadString(yourHTMLString, "text/html");
geckoSession.loadData("My First Heading. My first paragraph.".getBytes(StandardCharsets.UTF_8),"text/html");
geckoSession.loadString("<!DOCTYPE html><html><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html>","text/html") displays blank page. Awesome!

How to clear html page before showing into a webview in Android?

I have the URL of a webpage to be displayed into a webview in my Android app. Before showing this page i want to clear the html code of this page from some tag (such as the header, footer, ecc..) in order to show only few information. How can i do it? I tried to solve the issue working with JSoup but i can't understand how to create and pass the "new page" to the webview. Anybody can help me?
EDIT
I cleaned the html code useless through jsoup libraries. Then, always by mean of these, i get head and body content and finally i showing the "cleared" web page through these lines:
headURL = doc.select("head").outerHtml();
bodyURL = doc.select("body").outerHtml();
webview.loadData( "<html>"+headURL+bodyURL+"</html>" , "text/html", "charset=UTF-8");
webview.setWebViewClient(new DisPlayWebPageActivityClient());
The view shows the new page but do not load css files specified in the head(that has not been touched). Who can say me why?
You can fetch the WebPage you want to display as a string, parse and remove whatever you don't want and then load this string as data in your webview.
Something like:
String webContent = fetchPage(url);
String cleanedWebContent = cleanUp(webContent);
webView.loadData(cleanedWebContent, "text/html", "UTF-8");
Of course, you will need to implement fetchPage and cleanUp as they are not Android methods

How can I embed the new GIFV format on my android app?

I would like to know if one of your could embed GIFV format into your app. I am trying to embed it using a webview but without success.
Actually GIFV format is closer to a video format than a gif.
Whatever suggestion would be nice. Thanks in advance.
After work around of this issue, I couldn't find a solution which could display GIFV format like a video.
But, my solution to this issue has been to use a webview using the same way that i was using to make able to load "gif" files and if you remove directly the "v" from the name of the file, you can show it as a .gif file.
Resuming, remove the "v" from the .gifv file name and display it as a .gif.
The way that i am injecting code to make able to display gifs into the webview is:
public void getContentWebView(String url, WebView webView)
{
String html = "<!DOCTYPE html><html><body><img src=\""+ url +"\" width=\"100%\" height=\"100%\"></body></html>";
webView.loadData(html, "text/html", "utf-8");
}

Android webview image fullscreen on click

I am working on a developing an Android application that displays news articles from a database through JSON. The article is in HTML format because the database is used for both web and the app. The code I have (below) works great. The format is the same on both web and phone when displayed in a webview, but I would like the images to be clickable, so they can can be loaded in a separate activity, and the user can zoom and such.
I guess I am just not using the proper wording when looking for an answer, because I cannot find anything that relates to this. I am assuming I would have to find the tags on click and capture the url somehow, and then pass it to another activity. I am not sure if this is the best way to do this or not. Any insight on this would be greatly appreciated.
web = (WebView) findViewById(R.id.WebView01);
final String mimeType = "text/html";
final String encoding = "UTF-8";
web.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
web.setScrollbarFadingEnabled(false);
web.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
web.loadDataWithBaseURL("", product.getString(TAG_CONTENT), mimeType, encoding, "");
This code runs within a Async task that queries the database for info.
Since it is HTML, you can use the onclick attribute of the img tag
<img src="myimage.png" onclick="javascript:window.location=this.src;" />
This will open the image up as the current window.
Or you can do something similar to this answer and send the URL to another activity.

Android - Problem in using the Google pdf viewer in webview

I have seen lot of threads about loading a PDF in Android Webview. But I didn't see the issue what I am getting.
I am using Google PDF viewer to load the URL in the Webview which will give a PDF as response.
I am setting the following properties to my webview
mWebview.setWebViewClient(new WebViewClient());
mWebview.setVerticalScrollBarEnabled(false);
mWebview.getSettings().setJavaScriptEnabled(true);
Webview.getSettings().setDefaultZoom(ZoomDensity.MEDIUM);
String url = "http://docs.google.com/viewer?embedded=true&url=" + "my url";
mWebview.loadUrl(url);
I am able load the PDF with the above given code. The issue I have is,
Once after loading the full page, a empty line is keep on getting inserted in top and bottom of page. So my page is looking like the one given below.
empty line
empty line
empty line
....
pdf content
empty line
empty line
empty line
....
The page is keep on increasing with empty lines.
There was something wrong with Google only, now I am not getting this issue, it works fine.

Categories

Resources