question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 5 years ago
  • Comments:25 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
cvalierecommented, Aug 17, 2018

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:

  • Instead of relying on a global object injected into window (in your case, window.BackgroundGeolocation), you import a Typescript class injected in your constructor, which is cleaner. Note that, in the end, this Typescript class still calls the global object of your plugin, so it’s only cleaner in appearance
  • As it is Typescript, you benefit from the typing: when you do import { BackgroundGeolocation, BackgroundGeolocationConfig, BackgroundGeolocationResponse } from '@ionic-native/background-geolocation', those objects that you import define their attributes and methods, which helps you during development

Why the Ionic-native wrapper doesn’t work with v3.x

very simply, because you changed the name of your global object, from backgroundGeolocation to BackgroundGeolocation so, when you call the ionic-native wrapper, it in turn calls backgroundGeolocation, which doesn’t exist anymore; and that’s why it tells you that you didn’t install the plugin

So, 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!

3reactions
dreadnautxbuddhacommented, Oct 8, 2018

Hi @cvaliere (<any>window).BackgroundGeolocation; is indeed working. I just had to remove/add the android platform again. Thanks a lot!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ionic android button not working - Stack Overflow
Im facing a problem with my ionic app. I coded the whole app over the webbrowser through ionic serve. Now I want to...
Read more >
Ionic android build problem
Anyone guess what is the problem? error log `Prosenjits-Mini:ionicwordpress prosenjitmanna$ ionic build android. Running command: /Users/ ...
Read more >
Ionic android buil fails - RevenueCat Community
Hi, so we are using ionic capacitor framework. Everything works fine on IOS but we have problem with Android. So when we start...
Read more >
Generate App Icon and Splash Screen Images for Ionic ...
A handy script to help you generate app icon and splash screen images for your Ionic app using Capacitor. Ionic Framework is awesome...
Read more >
Navigate Between Pages In An Ionic Android And iOS App
The UI-Router is not present in the latest version of Ionic Framework. We're going to take a look at navigating around an Ionic...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found