I would like to know when a user arrives or leaves certain location. I was trying to do this using the wireless network (check for mobile devices), but I couldn't for several reasons.
1) I needed real time updates or every 1 - 5 min of the information about which devices are connected and which devices have just disconnected.
2) I had very high ping from my PC to my iPhone on the same network (still don't know why).
Now I want to do it using geolocation from a Phonegap application (running in the background) suspended on iOS or running in the background in Android.
Any help would be appreciated.
Update 25 May 2019
My original answer below is 6 years old and out-of-date with respect to current mobile OS versions.
For example partial wakelocks no longer work on modern Android versions.
Today my recommendation would be (if you have a serious commercial app and not a hobby project) to use the paid-for version of the cordova-background-geolocation plugin by Transistorsoft.
The free version works for iOS but for Android a license is required which costs in the order of several hundred US dollars.
However I think the price is worth it: in my 10+ years of experience in creating location-aware mobile apps, this has been the most sophisiticated and reliable solution I've encountered.
For the cost of your license, you get access to the private repo which is continually updated and maintained to be compatible with new versions of Android & iOS.
If you're looking for a free/open-source solution, I would go with cordova-plugin-background-geolocation which is an open-source fork of the original plugin by Transistorsoft.
However my experience with this plugin has been of mixed success; due to being free/open-source, it's not updated as frequently as the paid-for Transistorsoft plugin.
I encountered problems due to new more stringent restrictions on background location in recent versions of Android which took a significant time to be resolved or have not been fixed at all (see the plugin's issue list).
Original answer (11 Jun 2013)
The first thing to say is that creating a Phonegap app that receives location updates while running in the background is entirely possible, but not trivial. I've done it myself and released apps on both the Android and iOS platforms.
If you need accurate and regular position updates, I'd suggest using the GPS receiver on the target devices. In Phonegap, you can do this setting the "highAccuracy" flag when requesting position updates. The watchPosition() function will deliver new position information as and when the device receives updates from the GPS receiver, so you use it something like this:
navigator.geolocation.watchPosition(successCallback, errorCallback, {
enableHighAccuracy: true,
timeout: 10000,
maximumAge: 0
});
See the Phonegap geolocation API documentation for more details (note the permissions that are required to make this work on Android and iOS).
To keep your app running in the background on either Android or iOS you will need to setup their respective native development environments: Eclipse for Android, XCode for iOS. You will not be able to use Phonegap Build because custom settings are needed in both cases to make it work. See the Phonegap platform guides for how to do this.
To keep your app running in the background on Android, you either need to write a custom Android service, or you could do what I did and use a Phonegap plugin to acquire a "partial wakelock" (see here) to keep your app running in the background and receive position updates while the screen is off. Note that the original version of this plugin is out-of-date and doesn't work with more recent versions of Phonegap, and also doesn't support partial wakelocks. However, I've updated and extended it for my own use: you can find the source code for it in my answer to this question.
To keep your app running in the background on iOS, you need to do things slightly differently; you don't need a plugin, just a project setting.
You can either manually edit the project .plist and add the key “UIBackgroundModes” key with a value of “location” or, with your project open in XCode, add the "Required Background Modes" key with a value of "App registers for location updates". This will cause iOS to trigger the JS callback function you have registered with watchPosition() each time a location update is received. See here for more about iOS project keys and background modes.
Hope this helps!
Related
I'm currently building an Ionic app which will be getting very frequent updates. If possible, I want to avoid sending users to the app/play store each time I push a change (which will probably happen at least twice per month).
I use the coinmarketcap mobile app a lot which seems to be built on some sort of browser rendering engine (although I don't know which one). Often, when I open this app, I get a small changelog informing me that there was an update, and can immediately start using those new features, without having to manually download the app.
Is it possible to build such an automatic update system with Ionic (React) 6 (w/o Appflow)?
I am familiar with web tech (html5) and want to build an app to track location in background in every 5 mins. so, the required features include auto start, GPS location, run in background in every 5 mins.
I want to know if i do it with an pure web tech. if not, which html based framework can do it well, such as RN, WEEX, Angular?
thanks very much!
I did some research these days and have my answer here. I preferred the solution with Ionicframework with Cordova and its plugins.
if I did a correct search, I can get the answer quickly. This https://github.com/mauron85/cordova-plugin-background-geolocation provided a solution for me.
why choose Ionic?
Ionic provided a framework to build an app for devices, desktop, and web. It is not a perfect solution but can help me deliver my app to all platform easily. I am not sure if Ionic is OK to build a high-quality app because it depends on some immature library or tools. But it can reduce lots of work to build a prototype with limited resource. What you need just an HTML5 developer.
I do not choose RN because RN only supports Device. cannot be deployed to desktop and published as web app.
I'm having some errors with running a developed application on a device with android 6.0.1 that runs perfectly on a device with Android 2.3.6. I'm using the same built application (compiled for an Android API 10) for both devices.
The errors are about the application being closed when a new Activity starts and when a contact is selected, I know how I could solve those problems for that device, but problem is that from what I had read I thought that android had no problems with being functionally backwards compatible (maybe there could be some graphical issues but nothing that would make the application crashing, as it is happening to me).
So I'd like to know if this is just some exceptional event that has happened to me, and the most likely thing is that, once I check these errors in some more android versions and fix the code of the app to run on them, something like these errors is not going to happen again, or if events like that are relatively common. If that's the case it sounds pretty painful to have to check and maybe develop accordingly for a lot of versions, so I'd like to know if there's some shortcut which, even if it doesn't offer 100% security of having the application correctly functionally developed, it gives a good percentage of security.
I think in general an app is forward compatible, but only if you ensure that you don't make use of private or undocumented api's.
For example when I first started playing with android there was a bunch of info on the web on how to send and received text messages that were not mentioned at all in the google documentation. Using that info (undocumented api) would have caused my app to break when KitKat came out and introduced and officially documented api for that particular purpose, since at the same time they removed the functionality that was available in the undocumented api. See here for details. of the above example.
Here is a link to some info on compatibility:
https://developer.android.com/guide/topics/manifest/uses-sdk-element.html
And a snip-it of the relevant section
Application forward compatibility Android applications are generally
forward-compatible with new versions of the Android platform.
Because almost all changes to the framework API are additive, an
Android application developed using any given version of the API (as
specified by its API Level) is forward-compatible with later versions
of the Android platform and higher API levels. The application should
be able to run on all later versions of the Android platform, except
in isolated cases where the application uses a part of the API that is
later removed for some reason.
Forward compatibility is important because many Android-powered
devices receive over-the-air (OTA) system updates. The user may
install your application and use it successfully, then later receive
an OTA update to a new version of the Android platform. Once the
update is installed, your application will run in a new run-time
version of the environment, but one that has the API and system
capabilities that your application depends on.
In some cases, changes below the API, such those in the underlying
system itself, may affect your application when it is run in the new
environment. For that reason it's important for you, as the
application developer, to understand how the application will look and
behave in each system environment. To help you test your application
on various versions of the Android platform, the Android SDK includes
multiple platforms that you can download. Each platform includes a
compatible system image that you can run in an AVD, to test your
application.
I'm looking into developing a cross-platform mobile app using Intel XDK and Cordova.
The scenario is like this:
Every n minutes (e.g. n=5) check a specific URL for updates.
If there are any updates, show or increment the badge on the app icon.
Before you say "use push notifications!" let me explain a bit more. The app I'm building will use a third-party API. Every user should keep a state of what's been seen / not seen. If I were to use push notifications I'd have to build my own backend and API that consumes the third-party API, store the state for every user and send push notifications on every update. That does seem like a major overhead.
For such a scenario iOS has 'background app refresh' since version 7. I would like to use this, but not sure how to.
So, what I would like to know is:
Can I use the background app refresh functionality through Intel XDK / Cordova and how?
How would this work for Android devices?
Actually my application is running a service only when boot completed. it runs fine in android 2.2.
But when i install 4.0 android supported device it does not work. even after installation application is not running. I know after 3.X android have a change that application is not running when installed.
So how only service oriented application run in > 3.x android version ?
any help is appreciable.
How to run application without activity in android version 4.X
You don't.
First, you pretty much always need an activity:
You need to have your copyright notice somewhere
You need to have your license agreement somewhere
You need to have your disclosures of other open source components that you are using somewhere
You need to provide access to technical support, even if it is just a link to your Web site, somewhere
You need to allow the user to configure the behavior of the service somewhere
You need to give the user access to online help somewhere
You want to avoid the one-star ratings that come from apps that do not have a launcher activity, when the user installs the app, then cannot figure out how to run the app, and thinks that you are a complete moron as a result
This is above and beyond the technical requirement for a component of your app to be manually started before any manifest-registered BroadcastReceivers will work.