Saurabh Khare
Saurabh Khare

Reputation: 1277

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 :)

Upvotes: 2

Views: 4474

Answers (1)

Pravin Sonawane
Pravin Sonawane

Reputation: 1833

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.

Upvotes: 2

Related Questions