2

I was trying to follow the documentation on apache cordova on how to embed webview to an android project. Here is the link http://cordova.apache.org/docs/en/2.5.0/guide_cordova-webview_android.md.html . I was stuck at 4th point because i dont have a main.xml file. I am not sure if the documentation works for the android platform ina cordova project. If this doesnt help, where can i find documentation to embed webviews. I tried to lookup but no success so far. Help is greatly appreciated.!

user3869280
  • 55
  • 1
  • 9
  • So, do you already have a cordova project setup? If so, you do not need to add a webview. The documentation you are referencing is for adding a cordova webview to an existing natively built android application. – Dawson Loudon Jul 25 '14 at 15:59
  • Yes sir. I have setup the cordova project. SO you are saying there is no need of webview for cordova projects. If so, how do i access my app through web. I have no clear idea of what a webview is. It is confusing. could you please share your knowledge. – user3869280 Jul 25 '14 at 16:14
  • @user3869280 A `webview` in XCode is an Object that will display a website on the device's screen. For example Safari Mobile uses a webview or any other browser app that needs to display websites. The link you posted is for native Android apps. I guess you are trying to build an cordova application with HTML/CSS/JS? If so, you won't need a webview (unless you are developing a browser app). The **index.html** file in the **www** folder is were you code has to go. – zk_mars Jul 25 '14 at 16:29
  • A cordova project is a native application that has a default view that is a webview. This is so that you can write html/css/js and have it run as a native application on a device. If you have a cordova project setup, there already is a webview and you dont have to do anything with it. Just go into the `www` folder of the project and start building your application with html/css/js. – Dawson Loudon Jul 25 '14 at 16:35
  • OK. so now how to access my app on a mobile device that i already installed my app. Yes, i am working towards integrating this hybrid app with a webapp thats already developed. My app is a scan reader. so i want my app to be integrated on the browser as a button and when one clicks the scanner should start and readback the results to the browser. If you could steer me towards the right path, I will be really grateful. Thankyou – user3869280 Jul 25 '14 at 16:41
  • my answer may help point you in the right direction. Are you using the Cordova CLI to initialize a project? – Lorenzo Jul 25 '14 at 16:47
  • yes. I used CLI to initialize the project. I put my apk file on tomcat inside ROOT and i can access the app through localhost url. It asks me to download. Its fine untill here. And now i tried to create a button and link a url to the button so it will ask me to download again but it isnt :( I used this code in a jsp page.
    – user3869280 Jul 25 '14 at 17:04

1 Answers1

2

as Dawson has pointed out, a cordova application essentially is a webview

What is a View A view is a native class which handles layout and interaction with the user. All mobile platforms have some form of this abstraction, and they are highly analogous. iOS has UIView and UIWebview, Android has View and Webview classes, Windows Phone 8 has WebView, etc. There are many many different types of view, each providing something different.

What is a WebView A webview is a browser without the chrome (ui). That's pretty much it. It's a browser, it has a DOM, a js runtime. It can load URL's.

What is Cordova Webview Cordova Webview is a subclass of the native android webview class, which enables cordova to do its magic. It has a variety of extra functionality to support the cordova api's (native-js communication bridge, plugins, etc). It's the container that your cordova app runs in.

Why you probably don't need to worry too much about it Unless you want to mix the cordova webview with other native views (a rare and complex use case), you absolutely don't need to worry that your app even runs in a webview. It's just the container.

initialize your project with the Cordova CLI

$ cordova create BAZ && cd BAZ
$ cordova platform add android
$ cordova run android

this will create a project, add the android platform, and run it. The HelloWorld app you should see on your device or emulator is the HelloWorld app in the www/ project directory running inside an Android webview.

Hope this helps!

  • Lorin
Community
  • 1
  • 1
Lorenzo
  • 413
  • 2
  • 8
  • thanks for the info. i have already done the steps following your guide lines. How do i access my app on a browser? is there any url that can lead me to open my app? My app is installed on my phone and runs successfully. now i want to open it when i click a button on browser. – user3869280 Jul 25 '14 at 17:01
  • Yeah! Your app will have it's own icon like any other app. However, you can open apps from the browser using Android intents! Check out this SO answer for how http://stackoverflow.com/questions/525063/android-respond-to-url-in-intent – Lorenzo Jul 25 '14 at 17:11