I am trying to use WebView to show a local HTML file containing a table. However, when I use the WebView to check websites online it works perfectly, the problem is when i try to use the local HTML file.
This is the webView part of the code:
WebView myWebView = (WebView) v.findViewById(R.id.webview);
myWebView.loadUrl("file:///asset/table.html");
I have used an online host to test the HTML file with this and it worked perfectly:
myWebView.loadUrl("http://ahmad92billectric.host56.com//home.html");
the HTIML file is in app\src\main\asset, I tried calling it using the following ways:
myWebView.loadUrl("file:///andriod_asset/table.html");
myWebView.loadUrl("file:///app/src/main/assets/table.html");
myWebView.loadUrl("file:///android_assets/table.html"); //this one is assets with an s at the end
I looked up many questions here non of the answers worked for me:
Loading existing .html file with android WebView
What does file:///android_assets/www/index.html mean?
Android webview loadurl("file:///android_asset/index.html#home") failed
Android Studio Assets not loading Local HTML File
I have checked many other questions with no fruitful results. I am using android studio 0.8.14
Use file:///android_asset/table.html, which is none of your listed attempts.
You can see that in use in this sample project, though the file here is geoweb1.html:
#SuppressLint("SetJavaScriptEnabled")
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
browser=(WebView)findViewById(R.id.webkit);
myLocationManager=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
browser.getSettings().setJavaScriptEnabled(true);
browser.addJavascriptInterface(new Locater(), "locater");
browser.loadUrl("file:///android_asset/geoweb1.html");
}
Related
I'm using the standard Android SDK with Ecliple as provided from the Android website.
What I want to to is to have an activity display a WebView that loads a local HTML-file. Everything works fine until I try to load the webview.
I've placed all the index-files I've tried in the project's assets-folder.
This is the code in my activity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView webView = new WebView(this);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("file:///android_assets/www/index.html");
setContentView(webView);
}
When I run the app over ADB, I get the following message in the WebView:
Webpage not available
The webpage at file:///android_assets/www/index.html might be temporarily down or it may have moved permanently to a new web address.
I know this problem has been posted before, and I've tried every single solution out there. But it just won't load. It displays online http-addresses just fine, but it doesn't seem to find any of the local files.
Please help me, this drives me mad.
Change this line:
webView.loadUrl("file:///android_assets/www/index.html");
to this :
webView.loadUrl("file:///android_asset/www/index.html");
is android_asset not android_assets :D. Good Luck
I am new to android programming and I am developing my first apps using eclipse.
I have kept my html and jquery codes inside assets folder.
now this is my code in mainactivity.java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView webView = (WebView)findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
// webView.setWebChromeClient(new WebChromeClient);
webView.loadUrl("file://android_asset/www/index.html");
}
when i installed app on my device and run it,
it says,
webpage not available,
the file at file://android_asset/www/index.html may have been moved permanently
plz help me to solve this
Try changing
webView.loadUrl("file://android_asset/www/index.html");
by
webView.loadUrl("file:///android_asset/www/index.html"); // please see the extra forward slash, they have to be 3.
So I have been looking everywhere and doesn't seems to find working answer for this. I have dynamic html page create using iMapBuilder and it has 3 external js files. Before I have added dynamic contents html was working just fine being under assets directory with following command:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ground_floor);
WebView wv;
wv = (WebView) findViewById(R.id.webview);
wv.getSettings().setJavaScriptEnabled(true);
wv.loadUrl("file:///android_asset/imap5custom.html");
}
}
After adding dynamic content with 3 Java Script external files which are also under root assets folder, html doesn't work any more. I have tried:
mWebView.loadDataWithBaseURL
but still didn't work for me.
hi I have Android App as I embed HTML file , I added my code and when I test the app I noticed that some of css classes doesn't called as #media also the JQuery doesn't called .
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_elaraby_group);
WebView wv=(WebView) findViewById(R.id.web_engine);
wv.loadUrl("file:///android_asset/index.html");
}
Well you have to provide exact same structure you are using in html page in your asses folder.Otherwise it will not get some files referenced in your html file.And hence those CSS and JavaScript code never gets run.So try with providing same structure as your localhost server.
I'm dealing with the following problem:
I have a webview inside an activity:
webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDatabaseEnabled(true);
webView.getSettings().setBuiltInZoomControls(false);
webView.getSettings().setSupportZoom(false);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setScrollbarFadingEnabled(false);
webView.setWebViewClient(new HelloWebViewClient());
System.out.println("percorso" + path.toString());
url.setText(path.toString());
webView.loadUrl("local path of my html file" .....\..\..page.htm);
private class HelloWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
This is the app I'd like to run locally offline: http://miniapps.co.uk/checklist/
If I open the browser and i go to the link above everything works fine, so the android browser is actually able to run it.
Now I have downloaded this app and I stored it in a folder on my sd card: download/myapp
in the folder I have the html file: check_list.htm and a folder (check_list files) with the javascript files needed to run it.
But when i open it inside my webview, the page is correcty loaded but doesn't work...i can't click on buttons and other elements, i can't actually interact with it....
I thought it could be a problem related to my webview settings so i used astro file manager to surf into my sd card, i clicked on check_list.htm, i chose html viewer and i got the same issues....
So I downloaded opera mobile, and i did the same but this time I opened it with opera and now it's working correctly.
Do you know why? How can I fix the problem? Am I missing some settings on my webview or is the webview\android broser that hase some problems opening locally stored html pages and running linked javascript files?
EDIT
If I open the android browser and I write the path of the HTML file, it works. I have to do it manually cause if I click on the HTML file, android browser it's not an option......so in the end it works both on android browser and opera, and it doesn't with HTML viewer and my web view.....so I'm missing some settings cause the web view should have the same features of the android browser....shouldn't it?
If "doesn't run" mean it does not open new windows, that's because you need to specify the webview client.
From the Javadoc for WebView
By default, requests by the HTML to open new windows are ignored. This is true whether they be opened by JavaScript or by the target attribute on a link. You can customize your WebChromeClient to provide your own behaviour for opening multiple windows, and render them in whatever manner you want.
See https://stackoverflow.com/a/3847016/94363 or rtfm...
Please confirm before, your local file is inside asset/www/index.html directory.