I am trying to show doc/docx file using WebView in android - android

I am trying open a base64 string in WebView which is actually a doc/docx.
I have tried many ways, I don't wanna end up having paid library.
Here is my code. Please suggest...!
String lBase64Str =
Base64.encodeToString(lBytes, Base64.DEFAULT);
URL lUrl = new URL(lBase64Str);
lWebView.loadUrl(lUrl.toString());
lWebView.loadData(lBase64Str,"text/html","base64");

Related

Webview doesnt load image with String Html

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/"

How to open blob link use webview of android?

I want to display video in android app.
The link of video is blob link so that i think i need use webview to display it.
How to implement it?
WebView support loading HTML data from string. So following code is possible.
String videoBlobLinkUrl = "data:video/mp4;base64,[video base64-encoded data ..]";
String videoBlobMime = "video/mp4";
String videoHtml = "<html><body><video><source type=\""+videoBlobMime+"\" src=\""+ videoBlobLinkUrl +"\"></video></body></html>";
webview.loadData(videoHtml, "text/html", null);

Android: How to display .mht file?

I'm trying to display .mht file in Android, so I used webview like this:
byte[] bytes = tblK.getmhtmlFile();
String s = new String(bytes);
webview.loadData(s,"text/html;charset=utf-8","UTF-8");
and, it shows like this:
How to avoid those unwanted content from webview ?
Please help me, thanks in advance.
Webview is not a perfect one, It does not support mht files directly. I suggest you to try the below options for displaying mht files.
1.Android Custom Tabs
2.Chormium Webview Library

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 shows html instead of the pdf or document

I have a webview with javascript enabled and I'm attempting to display pdf, docs, etc... using google docs view url. The problem is that the webview is rendering html instead of the doc. I should mention that this also occurs with a url to a pdf or doc from my dropbox account.
string pdf = "https://docs.google.com/document/d/1SGFAxaYSA2wBvKCKL89rYG4yEZIJVIJ2lY-1G7IF6g4/edit?usp=sharing";
webViewcontent.LoadUrl("https://docs.google.com/gview?embedded=true&url=" + pdf);
This is what is showing:
I think the url you are looking for is...
string url = "https://docs.google.com/document/d/1SGFAxaYSA2wBvKCKL89rYG4yEZIJVIJ2lY-1G7IF6g4/edit?usp=sharing";
string myUrl = string.Format("https://docs.google.com/viewer?url={0}", url);
webViewcontent.LoadUrl(myUrl);
This will work without the user having a google account.
However, since your url is using https it may require authentication.
string pdf = "https://docs.google.com/document/d/1SGFAxaYSA2wBvKCKL89rYG4yEZIJVIJ2lY-1G7IF6g4/edit?usp=sharing";
webViewcontent.LoadUrl("https://docs.google.com/gview?embedded=true&url=" + pdf);
the final url of this will be https://docs.google.com/gview?embedded=true&url=**https://docs.google.com/document/d/**1SGFAxaYSA2wBvKCKL89rYG4yEZIJVIJ2lY-1G7IF6g4/edit?usp=sharing, I think you want to remove everything except for the document id.

Categories

Resources