alternative for web worker in android-phonegap? - android

can any one suggest me an alternative for phone gap web workers because i want my application to run successfully from android 2.2 to 4.2.
As i know web workers support for 4.0 and above.
I tried Android Google cloud messaging and that is working perfectly fine.
but i am looking for phone gap options not native android options.

You could try https://crosswalk-project.org, which enables you to use an modern version of a Chromium-based Webview and get rid of the system webview. It's an Intel project, the documentation is complete and concise, and it includes many examples of how to use it along Apache Cordova.
Note Web Workers API is listed as supported: https://crosswalk-project.org (as well as WebRTC, WebGL, or other less unheard-of niceties like Web Notification API, which would free you of using a Cordova plugin for launching system native notifications).
The Chrome team also made a tool for packaging Chrome Apps with Cordova via the Crosswalk Webview: https://github.com/MobileChromeApps/mobile-chrome-apps
Using Crosswalk has some caveats, though. See https://github.com/MobileChromeApps/mobile-chrome-apps/blob/master/docs/Crosswalk.md For me, the more important one is: "An increase of about 17MB in the size of the .apk file". Depending on the app type (mainly if it's not a game), I, as an Android user, won't install such big app.

You could try a combination of inappbrowser and the localStorage/'storage' events.
For example. YOur background processes could run in your index.html which would bind an event handler for 'storage' using window.addEventListener('storage', function callback, true/false)
When the page loads, before hiding the s splash screen, launch another browser instance using window.open directed to ui.html (containing ui thread/html/css ect) be sure to configure the browser to be full screen with all tool/ location bars hidden.
Now in the ui.html javascript when you want to send data to the bg thread you just create it in local persistent storage. Ex localStorage.setItem ('item', data);
Now an event should fire in the original window (bg layer) triggering your callback function which will be passed an event object that contains (amoung other things) the data value that changed.
If youd like more detailed instructions let me know. I got this working in android 2.2+

Use push notification plugin https://build.phonegap.com/plugins/3 that encapsulate Google cloud messagging on Android

Related

Use custom WebView Engine in ReactNativeWebview

I am using react native webview for my app show my website built on React & Vite.
The probl is that some users complain about the app showing a blank screen, after further investigation I found that the user should update 'Android System Webview' app and then every thing works fine.
But the other problem is that I am targeting a zero-tech experience users who might don't event know how to update apps.
So I thought about using custom engine for ReactNativeWebview like mozilla or using my own updated android system webview, maybe ?

Is there a way to update the data inside the application? Without updating the entire application?

I'm trying to build an application, "Journal for Drivers".
I would like to add new information to the driver in this application. This information will be in text format (or text with images)
My question is, if I want to add a news update to the application, a news for drivers, can it be solved for example by some storage on a server, where the application automatically downloads this news? Or do I have to write the entire app in Android Studio and update the original version of the app?
There are three main ways to accomplish this:
You can create a webpage and use webview component to load this website in your application. In this case you will have full control on the data (backend) while you can change the ui of this webview on the fly without releasing new versions of your application. called also hybrid application (which is part native you still need to create apk with this webview) and web part which will be where most of your code exists.
You can create a native application which will be written in native only (java or kotlin) in this way you will need to release a new version every time you will change anything in your application. (including logic change or ui change).
You can create PWA project which will simulate a "native" application in this way you control 100% of the code and it will based on web. You can open a url on your mobile browser and you could "install" a mobile version of the webpage on your mobile device which will simulate a "native" application it also other platforms such as iOS, windows and Mac (if I'm not mistaken)
This can achieved via an endless number of strategies. One such strategy uses deep links along with an API for this. For this to work, you will need to set up an online server which will serve as a back end. This is where you will post your news updates to an endpoint or endpoints. This can be implemented in many ways. For example, you may just hardcode your updates to the html, or more likely you will store each article to some sort of db. When a user of the app goes to view an article, it will send an HTTP request to the server asking for the article. The server will then retrieve said article from the db, process it in whatever way needed, and send it back to your app.
Using this method, you only need to change your article on the back end (or better yet add your article to db and update a pointer that points to current article).

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:
There is my vision of mobile application version with camera and image picker option right under web browser:
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.
If I interpreted your problem statement correctly, I believe what you are looking for is access to device native services - camera & gallery - from your mobile website.
A solution that fits your design requirements is for the browser to provide such services. Unfortunately WebKit and other browsers limit such support to things like Geoposition.
The way for Cordova to help you here is if your mobile website is an stand alone HTML5/CSS/JS application that can use CORS XHR or WebSockets to communicate with webindependent Web Services.
If you can bottle your website into a set of static html/js/css files that display content from dynamic web services then you are set. That same javascript can then call navigator.camera.getPicture(success, fail, options) and file-transfer the result to a waiting web service.
That camera api is not available to the InAppBrowser just as it is not available to WebKit Chrome/Safari/Edge. Trying to control the Mobile App via the InAppBrowser is most likely to fail due to security constraints.
What you might get away with is re-imaging your browser application as a series of discrete services that return raw html snippets suited for a new mobile app. Then write your Cordova app as the top level container that manages the navigation amongst the html snippets. This server-side rendering would be most useful if it was significantly challenging enough to overwhelm the mobile platform / web services pattern (think custom video server or expert system).
#Jakub,
Cedric has essentially stated it plainly. I will restate. You understanding about Cordova/Phonegap is not correct.
From: Top Mistakes by Developers new to Cordova/Phonegap
You have hit issue #5.
I QUOTE:
From Phonegap FAQ
A PhoneGap application may only use HTML, CSS, and JavaScript. However, you can make use of network protocols (XmlHTTPRequest, Web Sockets, etc) to easily communicate with backend services written in any language. This allows your PhoneGap app to remotely access existing business processes while the device is connected to the Internet.
In addition, Apple frowns on using apps as wrappers for websites.
Quote Apple iTunes Guidelines - 2.12
Apps that are not very useful, unique, are simply web sites bundled as Apps, or do not provide any lasting entertainment value may be rejected
To be clear, your idea may be valid, but you will likely need to rethink your internal workflow. You likely want to keep the same UI and UX.

Accessing device native features in cordova webview

I am making a Hybrid Application using cordova-cli. My requirement is that the first page in my application must redirect to a website. The entire data required for the application will be loaded into this website from some other data-sources.
The requirement is to access device native features such as camera, accelerometer etc. from pages on this website.
I am using
location.href="http://www.example.com";
to open the pages. I need a unified cordova.js file with all the plugins embedded into it.
Currently I am putting the individual plugins into the lib\android\plugin\android and by using the grunt -f command from grunt-cli, the cordova.js file recieved for android does not seem to produce expected results.
Can't be done I am afraid - because of the way Cordova interacts with the device.
What happens if, using a non-mobile device, you accessed the same website from elsewhere? The website will not know what on earth Cordova is.
Cordova interacts with the native code on the device, so requires this to handle the passing of JS-to-native, and vice-versa.

Ttitanium webview and HTML5 application cache

I am using Titanium to create a application for Android. The app uses webview to load external HTML5 webpages. The webpage uses a manifest to cache the page and some assets. This works fine on desktop browsers and third party app browsers in Android (Chrome).
When I view the page in a webview in the Titanium build app, it seems that the manifest is not used, the page just loads everything from the server. The same problem occurs when I use the build in browser of my phone (HTC one X).
What I am trying to accomplish is that the pages are offline available, so that internet is not required tot view cached pages. Is there a fix for this problem, or should I go look in another direction to solve my problem?
the manifest file:
CACHE MANIFEST
# version 1
leerlingen.html
jquery.js
style.css
handler.js
NETWORK:
*
First: Titanium provides much more than a WebView. If you planned to display only web pages you maybe should have a look at PhoneGap / Cordova which might fit your needs in a better way.
As you've noticed not all browsers support HTML5 Caching feature as expected. I can't say if it doesn't work for Android in general or only for your specific version because WebKit usually does support it but it depends of the used WebKit version. And this could be different.
EDIT: It seems that (in native android) this feature can be enabled as written here: Application cache in HTML5 doesn't work in Android PhoneGap application. This is currently not possible in Titanium (there might be inofficial tweaks i don't know but from http://docs.appcelerator.com this is not possible).
Personally i'd prefer another solution. Cache data by myself and display it if there is no network connection. But this depends on what you try to achieve. Having few content which doesn't change often this would make sense. Having dynamically changing data (like twitter stream for instance) this would be difficult. Also it depends on your users and where they want to access your app.
And there is an open question: When you want to use all the caching features why do you want to create an app? Creating a simple mobile webpage would do the same job. When creating an app i wouldn't use the Caching Features of HTML 5. You should keep all the static resources in your app and simply load data from the network. This can be achieved by both Titanium and PhoneGap / Cordova. Titanium is more useful for a native UI and some native Features while PhoneGap / Cordova would be more appropriate for HTML5 based layout.
Just in case someone else is running in the same problems that i was facing, here is what i've done. HTML5's application cache does not seem to work in the build-in browser of Android and with that the webviews. In Titanium there seems to be no way to control the webview as to enable the application cache.
The work around for me was to use Titanium and it's httpClient function (Titanium.Network.HTTPClient) to request the files (HTML, CSS, javascript) and store it in the local app filesystem (Titanium.Filesystem).

Categories

Resources