Geofencing no notifications


#1

I am trying to use geofencing in one of my Ionic-3 apps. After floolwing the instructions in https://ionicframework.com/docs/native/geofence/, I modified my app.components.ts that now looks like this:

import { Geofence } from ‘@ionic-native/geofence’;

@Component({ templateUrl: ‘app.html’ }) export class MyApp {
constructor(private geofence: Geofence) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
statusBar.styleDefault();
splashScreen.hide();
this.startGeofence();
});
this.pages = [
]; }

startGeofence() {
// initialize the plugin
this.geofence.initialize().then(
// resolved promise does not return a value
() => {
console.log(‘Geofence Plugin Ready’);
this.addGeofence();
},
(err) => {
console.log(‘Geofence Plugin failed’);
console.log(err);
}
) }

private addGeofence() {
this.geofence.removeAll();
//options describing geofence

let fence = {
  id: '69ca1b88-6fbe-4e80-a4d4-ff4d3748acab', //any unique ID
  latitude: 41.2713354, //center of geofence radius
  longitude: 18.6108311,
  radius: 20, //radius to edge of geofence in meters
  transitionType: 3, //see 'Transition Types' below
  notification: { //notification settings
    id: 3, //any unique ID
    title: 'Geofencing', //notification title
    text: 'my home', //notification body
    openAppOnClick: true //open app when notification is tapped
  }
}

this.geofence.addOrUpdate(fence).then(
  () => console.log('Geofence added'),
  (err) => console.log('Geofence failed to add')
);

this.geofence.onTransitionReceived().subscribe(resp => {
  resp.forEach(function (geo) {
    console.log("Geofence transition detected", geo);
  });

  console.log("geofence on transition recieved", resp);
  alert(JSON.stringify(resp));
});   } }

In the console log I have the following messages:

deviceready has not fired after 5 seconds. Ionic Native: deviceready
event fired after 4964 ms Geofence Plugin Ready Geofence added

those show a correct initialization of the plugin, but, after that, nothing happens, the onTransitionReceived is never called.

My package.json:

{ “name”: “ClientIonicProject”, “version”: “0.0.1”, “author”:
“Ionic Framework”, “homepage”: “http://ionicframework.com/”,
“private”: true, “scripts”: {
“clean”: “ionic-app-scripts clean”,
“build”: “ionic-app-scripts build”,
“lint”: “ionic-app-scripts lint”,
“ionic:build”: “ionic-app-scripts build”,
“ionic:serve”: “ionic-app-scripts serve” }, “dependencies”: {
@angular/common”: “^5.0.1”,
@angular/compiler”: “^5.0.1”,
@angular/compiler-cli”: “^5.0.1”,
@angular/core”: “^5.0.1”,
@angular/forms”: “^5.0.1”,
@angular/http”: “^5.0.1”,
@angular/platform-browser”: “^5.0.1”,
@angular/platform-browser-dynamic”: “^5.0.1”,
@ionic-native/app-version”: “^4.4.0”,
@ionic-native/core”: “4.3.3”,
@ionic-native/geofence”: “^4.7.0”,
@ionic-native/geolocation”: “^4.4.0”,
@ionic-native/http”: “^4.4.0”,
@ionic-native/in-app-browser”: “^4.4.0”,
@ionic-native/launch-navigator”: “^4.4.0”,
@ionic-native/network”: “^4.5.2”,
@ionic-native/splash-screen”: “4.3.3”,
@ionic-native/status-bar”: “4.3.3”,
@ionic-native/text-to-speech”: “^4.4.0”,
@ionic/storage”: “^2.1.3”,
@ngx-translate/core”: “^8.0.0”,
@ngx-translate/http-loader”: “^2.0.0”,
“cordova-android”: “6.3.0”,
“cordova-plugin-actionsheet”: “^2.3.3”,
“cordova-plugin-add-swift-support”: “^1.6.0”,
“cordova-plugin-advanced-http”: “^1.11.1”,
“cordova-plugin-app-version”: “^0.1.9”,
“cordova-plugin-compat”: “^1.2.0”,
“cordova-plugin-device”: “^1.1.4”,
“cordova-plugin-dialogs”: “^2.0.1”,
“cordova-plugin-file”: “^6.0.1”,
“cordova-plugin-geofence”: “^0.7.0”,
“cordova-plugin-geolocation”: “^3.0.0”,
“cordova-plugin-inappbrowser”: “^1.7.2”,
“cordova-plugin-ionic”: “^3.1.3”,
“cordova-plugin-ionic-webview”: “^1.2.1”,
“cordova-plugin-network-information”: “^1.3.4”,
“cordova-plugin-splashscreen”: “^5.0.2”,
“cordova-plugin-statusbar”: “^2.4.2”,
“cordova-plugin-tts”: “^0.2.3”,
“cordova-plugin-whitelist”: “^1.3.1”,
“cordova-sqlite-storage”: “^2.3.1”,
“es6-promise-plugin”: “^4.2.2”,
“ionic-angular”: “3.9.2”,
“ionic-plugin-keyboard”: “^2.2.1”,
“ionicons”: “3.0.0”,
“rxjs”: “5.5.2”,
“sw-toolbox”: “3.6.0”,
“uk.co.workingedge.phonegap.plugin.launchnavigator”: “^4.2.0”,
“zone.js”: “0.8.18” }, “devDependencies”: {
@ionic/app-scripts”: “3.1.0”,
“typescript”: “2.4.2” }, “description”: “An Ionic project”, “cordova”: {
“plugins”: {
“cordova-plugin-tts”: {},
“cordova-plugin-app-version”: {},
“cordova-plugin-geolocation”: {
“GEOLOCATION_USAGE_DESCRIPTION”: “To locate you”
},
“cordova-plugin-inappbrowser”: {},
“uk.co.workingedge.phonegap.plugin.launchnavigator”: {},
“cordova-plugin-advanced-http”: {},
“ionic-plugin-keyboard”: {},
“cordova-plugin-whitelist”: {},
“cordova-plugin-device”: {},
“cordova-plugin-ionic-webview”: {},
“cordova-plugin-network-information”: {},
“cordova-sqlite-storage”: {},
“cordova-plugin-geofence”: {},
“cordova-plugin-add-swift-support”: {},
“cordova-plugin-statusbar”: {},
“cordova-plugin-splashscreen”: {}
},
“platforms”: [
“android”
] } }

ionic info:

cli packages: (C:\Users\francesco\AppData\Roaming\npm\node_modules)

@ionic/cli-utils  : 1.19.2
ionic (Ionic CLI) : 3.20.0

global packages:

cordova (Cordova CLI) : 8.0.0

local packages:

@ionic/app-scripts : 3.1.0
Cordova Platforms  : android 6.3.0
Ionic Framework    : ionic-angular 3.9.2

System:

Android SDK Tools : 26.1.1
Node              : v6.10.3
npm               : 6.0.0
OS                : Windows 10

Environment Variables:

ANDROID_HOME : D:\e\programmi_esterni\Android\android-sdk

Misc:

backend : legacy

Suggestions?


Error using Geofence
#2

Did you find a solution for this? I’m struggling with the same problem and can’t find any helpful results when Searching the web


#3

Likewise. Please let us know if you’ve found anything


#4

nothing to do. I am blocked on this.


#6

I had this problem and managed to solve it. But it was all a bit of a nightmare as it involved modifying a java file that the plugin installs.

I’m also using the phonegap-plugin-push plugin and on Android 8 or above you should now create a channel (or several channels) for your app to use. You can set different priorities on each channel if you want. This lets your users decide which, if any, notifications they want to receive. There’s a rundown of these new features in this Android 8.0 Features and APIs doc.

Basically, as far as I can tell, the implementation of the notification builder class in the plugin Java file is not compatible with Android 8 or above as there is no channel id or priority set. I’m basing this upon this Android guide.

Anyway, I cloned the geofence plugin, modified the ‘GeoNotificationNotifier.java’ file in the cloned plugin Android src folder, and installed the plugin from my local source. Worked for my particular use case…