I asked a question before but the wording was all wrong and I don't think it explained what I really wanted to do so here goes;
I have a webview in my app that access a website that I do not own or run, the website has a iframe with the following information:
iframe id="download_file" scrolling="no" src="http://www13.online-convert.com/download-file/41ffbb25dc972bdee4abc02ea1164fea/converted-df4a80e3.mp3">/iframe
Its a link that downloads a file, however the android webview doesn't allow me to click the link and download the file.
I have now added a button to my app, what I want the button to do is the following;
1 - extract the src http address from the iframe (http://www13.online-convert.com/download-file/41ffbb25dc972bdee4abc02ea1164fea/converted-df4a80e3.mp3)
2 - save that http address as a string that I can use.
3 - download the file.
The issue is I have know idea how to use javascript or a simple java code that can use my webview to locate that http address and save it as a string.
I have tried several tutorials, I have looked every where for a answer, is this even possible what I am trying to do?
Please any help would be great.
Try this;
Create a file in your assets folder named sample.html
<html>
<a href="http://www13.online-convert.com/download-file/41ffbb25dc972bdee4abc02ea1164fea/converted-df4a80e3.mp3" >Link<a/>
</html>
and your activity class onCreate function use this codes.
WebView webview;
webview = (WebView) findViewById(R.id.webview);
webview.loadUrl("file:///android_asset/sample.html");
Related
im a new android developer.
My app has WebView which loads lot of data from my site (which has pics, css, JS files).only the html code is updated weekly. other files are almost never changed. so i was thinking of including these static files in android assets, loading only the html from server and other files from assets and cutting down the loading time. how do i do it.
Android WebView Javascript from assets
and as shown in the above solution i cant change the html code to load these from assets because this site will also be accessed by web users.
Is there a way to do this. Thanks in advance..
Firstly you need to have relative paths
<img src="images/someimage.png">
not
<img src="www.mysite.com/images/someimage.png">
Then you need to load the HTML code not using webBrowser, for example like here
And then you can load HTML source into WebBrowser using base URL pointing to your assets like here
I am creating an application and I am trying to load a HTML page in a web view.
I am using the code
WebView webView = (WebView)findViewById(R.id.webview);
webView.loadUrl("file:///android_asset/index.html");
but continue to receive an error that the web page at file:///android_asset/index.html might be temporarily down or it may have moved permanently to a new web address.
Any help would be great
from assets folder
webview.loadUrl("file:///android_asset/file.html");
from specific folder
webview.loadUrl("file:///data/data/com.example.example/files/file.html");
I am developing an android app. In that I have used webview to open the html page.
But some of the features on my HTML page would work only if I access the page through server.
How can I host the HTML page locally on my Android device?
For better Idea:
Example: On PC, I have hosted the html page locally using Apache Tomcat Server.
So to load this HTML page, I have two options
1. Directly double clicking the HTML and opening in browser.
2. Using URL: http://localhost:8080/MyWebApp
The first option is basic and some of features are not supported.
In second approach, all the features work as expected.
Is there any app/sdk/ open source which I can use to locally host the HTML page?``
try this code
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
//webView.loadUrl("file:///android_asset/folderName/index.html");
webView.loadUrl("http://10.0.2.2:8080/MyWebApp");
Put your file to assets folder and write this
webView.loadUrl("file:///android_asset/help.html");
I am currently having problems referenceing a a file created into internal storage from my web view. the same code can reference similar file through href from a web address but when I decided to save the same file into internal storage I get Web Page at /data/data/packageName/files/fileName.html might be temporarily down.... any help would be appreciated
The line below resulted in an error when clicked on Webview:
<a href='/data/data/packageName/files/fileName.html'>
in fact when I tried with file:// the click was completely ignored as in <a href='/data/data/packageName/files/fileName.html'>
Meanwhile the same line works with <a href="http://www.someweb.co.uk/fileName.html'> is there any known workaround?
My application has one button. If you click that button then it will display the web pages based on the web service response using webview.
It works properly for general links. But for links that have .pdf, a white screen gets displayed.
Is it possible to display the .pdf file using web view?
Would appreciate any help.
i used the following code
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("http://docs.google.com/gview?embedded=true&url="
+"http://www.kim-lai.com/images/Menu_100309.pdf");
It sounds like it could be trying to but there is no direct pdf rendering support in webview. Please look at the following question
android webview pdf
You may find the following question useful also
how to open a pdf file inside a webview for android?
EDIT
Android - Load PDF / PDF Viewer
Please also make sure you ask appropriate questions, prefrerably with code so that others can reproduce your problem and offer a solution. Do your own research!!! Stack overflow is not a magic site that does your work for you!!!
ADENDUM
You require internet permissions. Add this to your manifest.xml
SUPPLEMENTAL
I tried typing in the url into the browser and it tells me "Sorry, we are unable to retrieve the document for viewing or you don't have permission to view the document. "
mWebView.loadUrl("http://www.kimlai.com/images/Menu_100309.pdf");
Try like this, what do you see?