Android Application doesn't read css file completely - android

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.

Related

WebView does not work with local HTML files

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");
}

Android WebView not loading local HTML files

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

file://android_asset/www/index.html was not found

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.

Display HTML page with external JavaScript via Android assets

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.

phonegap android: opening another html file in the phonegap webview

i am building a phonegap(v1.3) android(for 3.1 sdk) app. i load the index.html page as in the sample app
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setIntegerProperty("loadUrlTimeoutValue", 60000);
super.loadUrl("file:///android_asset/www/index.html");
}
this works fine. now later on i want to load another abc.html file in the webview when i call for it from the js through a plugin. How to achieve a function like this which we can call from a Phonegap plugin.
public void loadUrl(String file){
super.setIntegerProperty("loadUrlTimeoutValue", 60000);
super.loadUrl("file:///android_asset/www/"+file+".html");
}
Or if not this way, how to load another html in the phonegap webview?
a simple
window.location.href = "file.html";
was the way. :(

Categories

Resources