Search code examples
androidioscordovawindows-phonemobile-website

What is the correct way developing website applications in Cordova?


I'm trying to do some simple website application for displaying my website and add some specific functionality to it.

My idea is to do something like Facebook app for mobile. Simply I need to display a website and replace File input - users should be able to capture a picture from camera or pick it from gallery (multiple select) and attach it to a post.

TL;DR;

Check images in the bottom.

What I have tried:

Using Cordova with Camera and Image picker plugin and displaying webpage in InnAppBrowser

Taking pictures with camera and picking pictures from gallery and then uploading them to server - there is a lot of examples of it.

What troubles I have found:

InnAppBrowser is forced fullscreen so I cannot resize it and place some buttons for picking pictures under it.

What do I need:

I just need to somehow attach images (from gallery or camera) to form file input or upload them to some kind of api instead - the api would process images on server and return some IDs which I can use instead of file input in the form on page to attach images to the post. Some hidden input where I would just insert IDs of uploaded images to be attached to the post (I'd write some if conditions into my PHP script).

I need my application to be multi-platform (Android, IOS, WP) so that is the reason I'm using Apache Cordova. I've tried lot of solutions and I've searched like for 5 hours. But I wasn't able to find anything useful.

Have somebody some experience in this way? Did somebody make some kind of that application?

If you can suggest any solution (it is not important to be a Cordova but it must be multiplatform) I'd be glad!

Thanks for your time!

Images

There is screen of desktop version with normal file input: desktop version

There is my vision of mobile application version with camera and image picker option right under web browser: mobile version


Solution

  • I guess I was not clear. The technical answer is Cordova/Phonegap are not for creating website applications. This means technically there is no "correct way" to do what you are asking.

    • For a website applications, all the pages are rendered from the website and controlled from the webpage/webbrowser.
    • For a mobile application, all the pages that the application can directly control are rendered on the mobile device. However, pages can be rendered (and/or created) from either the server or the mobile application, but the control of the page stays with the side that rendered (or created) the page. There is clear line between the two sides that can be moved, but at the *peril* of the programmer. (There are no points for being clever here, only added security issues.)

    However, the Cordova and Phonegap do have plugins.The entire purpose is to use plugins to make certain task easier. However, there is a clear line between the phone and the website. To be clear on this last part, this means that all of the "plugin services" on the phone (accelerometer, contact list, etc.) are directly available to the application, and not the website. However, some of the "services" are also available as HTML5 APIs, such 'camera' and 'geolocation' – mixing the two is dangerous. The HTML5 APIs should remain on the webserver side, if used. The UX is different for HTML5. (I will not discuss HTML5 APIs any further, as they are beyond the scope of this discussion)

    To make your idea work, you will need the following "core" (or equivalent third-party) plugins

    • file-transfer
    • camera (or equivalent)
    • inappbrowser

    On the file-transfer and camera, you can do everything from the webserver, if you want. Then the only task for the end-user is to select the appropriate folder and image. If you do this from the server-side, then you CANNOT use the plugins.

    If you want to use the plugins, then you cannot use a server-side generated webpage. You must create the form on the mobile device. This means the page and the form reside on the mobile device. However, if you write your webpage correctly you can dynamically add or delete elements. This means on the mobile side you have control over every step of the user experience and can enhance that experience.

    On the inappbrowser, a common trick is to put the website in an iframe. However, you have no direct control on the iframe. Another common trick is to submit to the server via an API – then have the visible webpage update separately. Another common trick is to have a webpage with a websocket that could handle the webpage update. However, this could also be done with a push to the webpage, or have the webpage do polling of the server. Again, the App has NO direct control of the webpage.

    This entire thread makes the following assumptions.

    • There is no "correct way" to do this task.
    • The images (photos) are stored on a website, and are publicly available for viewing.
    • It also assumes that no HTML5 APIs will be used.