Android application with AngularJS in webview - android

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.

Related

Android studio: How to artificially display a webpage?

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

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

Android Webview not reading CSS from my web server

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/

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