Android Webview not reading CSS from my web server - android

okay, here's the thing. I am currently working on android app which loads the url from my web server. the server contains the HTML and CSS im working on. when i run the app, the webview is not reading the css which is working properly when i load it in my web browser in pc.
Here is when i run the app/when i load it in mobile's browser: http://imgur.com/4Ev8WKc,t4YY6GA#1
Here is when i load it in my pc's browser: http://imgur.com/4Ev8WKc,t4YY6GA#0

Some solutions for the issue. Try these, don't know if they will solve as you haven't provided any code or url link with question.
Did you enable javascript in webview ? If not then enable using the code below :
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
There is a known bug in the file protocol for a few android versions. If you are referencing files with url parameters a HTTP 404 (file not found) occurs and the file is not loaded.
In your case the the styles.css might not be getting loaded.
Get help here :
https://coderwall.com/p/xnbawa
http://bricolsoftconsulting.com/fixing-the-broken-honeycomb-and-ics-webview/

Related

Android application with AngularJS in webview

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.

prevent favicon.ico from downloading

I want to view favicon.ico in the browser but not download them to my computer. How do I enforce that?
punch line
I have an app that is supposed to display favicons given a url. The app is successful only when the favicon.ico would display in browser as opposed to downloading. So I need to somehow force the image to display in browser. For example http://www.nydailynews.com/favicon.ico does not display in browser but rather downloads (chrome browser). But I see that safari is able to force it to display in browser. How can my android app do the same, as safari?
From android I am using picasso to load the images in a ListView
This is not a solution, but I'm not really sure what you're trying to do. Favicon does load in the WebView, it doesn't download it. I just tried the following code,
WebView view = (WebView) findViewById(R.id.web_view);
view.loadUrl("http://www.google.com/favicon.ico");
And this loads the icon in the WebView. Also I tried opening the same url in my Chrome Android app and it works too. It doesn't download it.
P.S. Note that I'm testing on Motorola Moto X running Android 5.1.
Update
Try this
WebView webView = (WebView) findViewById(R.id.web_view);
String data = "<body>" + "<img src=\"http://www.nydailynews.com/favicon.ico\"/></body>";
webView.loadData(data, "text/html", "utf-8");

Android HTML WebView

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

Can I use polymer/web components in a native android app w/o Cordova?

If I'm not mistaken, you need a web server to use/test Polymer's web components (such as the paper elements) on your computer due to browser permissions issues stemming from loading local file://s.
(A simple solution is to navigate to the directory where the polymer files are you want to try and type python -m SimpleHTTPServer then load http://localhost:8000 and all is good.)
But how about if I want to employ web components/Polymer elements in a native java android app inside a simple WebView w/o dealing with Cordova or setting up a web server somehow inside my app. Will I be able to do it easily, or will I have the same permissions issues?
Thanks in advance.
Yes! I'm hoping to write an article on this in the next few weeks. For the imports to load from file://, I've been successful with the following settings:
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true); // Enable Javascript.
webSettings.setAllowFileAccessFromFileURLs(true); // Enable HTML Imports to access file://.
Note: this is also using the Chrome webview (Android 4.4.3+).

Hosting HTML page locally in Android Device

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

Categories

Resources