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");
Related
I want to show the html file stored in localstorage when I access a webpage using chrome without being connected to the internet.
For example, if you try to access https://google.com without being connected to the Internet
<p>google.com</p>
I want the above html code to be displayed.
How can I perform the above tasks using android studio?
*(My native language is not English. Please forgive me if the sentence is awkward)
Use this code inside activity
WebView wv;
wv = (WebView) findViewById(R.id.webView1);
wv.loadUrl("file:///android_asset/aboutcertified.html");
How can I use AngularJS & H5 for building an Android native/hybrid app without using PhoneGap or Cordova, just simple webview inside android layout file.
Please provide some reference :)
Any AngularJS web app runs fine in a WebView.
To run the website in a WebView all you need to do is this.
final WebView containerWbVw = findViewById(R.id.fragment_wbVw_container_id);
WebSettings webSettings = containerWbVw.getSettings();
webSettings.setJavaScriptEnabled(true);
containerWbVw.setWebChromeClient(new WebChromeClient());
and then load the URL in the WebView using
containerWbVw.loadUrl(WEBAPP_URL);
The WEBAPP_URL can be an HTML page in your assets folder or hosted on your server
//assets folder file
WEBAPP_URL = "file:///android_asset/main.html";
//server link
WEBAPP_URL="https://mysite.mycompany.com/myapp";
In addition to this, you would need to interact with the native android app to send and receive data. For example, a use case would be to get a scanned barcode using the device's camera. For this, you would need a Javasrcript Bridge.
Is there a way to load an html page on a webview without using a web server?
In my android application I have a web server because the user can save the web pages he wants and he can access them offline later.
I tried the assets folder but I cannot modify it at runtime. I can just read files I´ve put there.
To load online or offline I use the methods of the webview:
browser is the webview.
browser.setWebViewClient(new client());
browser.getSettings().setJavaScriptEnabled(true);
browser.getSettings().setDomStorageEnabled(true);
browser.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
browser.getSettings().setUseWideViewPort(true);
browser.loadUrl(url);
The url can be :
http://stackoverflow.com a normal one
or
http://localhost:8080"; //the web server inside the app
or from assets folder
files:///android_asset/file.html
But how I said, the use can save many pages and see it when he wants.
Is there a method to load the page saved in internal memory on the webview?
URL =this.getApplicationContext().getFilesDir()+"/www/file.html";
browser.loadUrl(URL);
For example: webview.loadString(); ?
Something like browser.loadUrl(Uri.fromFile(f).toString()) should work, for a File object named f pointing to your desired file. Uri.fromFile() will give you a Uri with the correct scheme; toString() gives you the string representation to hand to the WebView. I use this (or a variation) to read files on external storage. AFAIK, it should work fine for files on internal storage as well.
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 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");