Not working alpha on ionic-android
See original GitHub issue- Plugin version: 3.0.0-alpha.37
- Platform: Android
- OS version: Ubuntu 16.04LTS
- Device manufacturer and model: Motorola Moto G
- Cordova version (
cordova -v
): 7.1.0 - Cordova platform version (
cordova platform ls
): android 6.3.0 - Plugin configuration options:
{notificationTitle: 'AP - Interno',
notificationText: 'Em execução',
desiredAccuracy: 10,
stationaryRadius: 50,
distanceFilter: 50,
debug: false, // enable this hear sounds for background-geolocation life-cycle.
stopOnTerminate: false, // enable this to clear background location settings when the app terminates
startOnBoot: true,
locationProvider: 0, /** ANDROID_DISTANCE_FILTER_PROVIDER: 0, ANDROID_ACTIVITY_PROVIDER: 1 */
interval: 10000,
fastestInterval: 5000,
activitiesInterval: 10000}
Context
Need upgrade from 2.x for 3.x why 2.x is not working has expected.
Expected Behavior
Init the plugin
Actual Behavior
The console is showing:
Native: tried calling BackgroundGeolocation.configure, but the BackgroundGeolocation plugin is not installed.
Install the BackgroundGeolocation plugin: ‘ionic cordova plugin add cordova-plugin-mauron85-background-geolocation’
When i run ionic cordova run android, however the plugin is installed. In package.json i see "cordova-plugin-mauron85-background-geolocation": "^3.0.0-alpha.37"
and in config.xml <plugin name="cordova-plugin-mauron85-background-geolocation" spec="^3.0.0-alpha.37">
Possible Fix
Steps to Reproduce
Install an fresh ionic aplication in latest version, install plugin and try run backgroundGeolocation.configure(config).subscribe
Context
This bug break my update to 3.x branch
Issue Analytics
- State:
- Created 5 years ago
- Comments:25 (1 by maintainers)
ok, I’ll try to explain as clearly as I can
Cordova plugins
A cordova plugin is a Javascript wrapper around native functions. It offers Javascript APIs that can be used in any Javascript code, with or without framework.
Ionic-native
Ionic-native is a TypeScript wrapper around cordova plugins. In other words, it’s an additional layer. So, when you call an ionic-native Typescript method, this method in turn calls the corresponding cordova Javascript method. The benefits of this additional layer are:
import { BackgroundGeolocation, BackgroundGeolocationConfig, BackgroundGeolocationResponse } from '@ionic-native/background-geolocation'
, those objects that you import define their attributes and methods, which helps you during developmentWhy the Ionic-native wrapper doesn’t work with v3.x
very simply, because you changed the name of your global object, from
backgroundGeolocation
toBackgroundGeolocation
so, when you call the ionic-native wrapper, it in turn callsbackgroundGeolocation
, which doesn’t exist anymore; and that’s why it tells you that you didn’t install the pluginSo, how can I use the cordova plugin in my Ionic application?
Well, ionic-native is absolutely not a mandatory thing to use a cordova plugin; it’s just an additional layer that helps people who develop in TypeScript. So, very simply, you can totally use a cordova plugin in an Ionic application just by following the documentation from that plugin!
Note also that ionic-native can absolutely be used in non-Ionic applications. Again, it’s just a TypeScript wrapper, it’s called “Ionic” because it’s the same team behind it, but that’s it.
Hope I was clear!
Hi @cvaliere
(<any>window).BackgroundGeolocation;
is indeed working. I just had to remove/add the android platform again. Thanks a lot!