Closed brainchild115 closed 5 years ago
Show me all the javascript you're using with the plugin.
class Geofence extends EventEmitter2 {
constructor() {
super();
this.geofencesRegistered = undefined;
this._setup();
}
static instance() {
if (typeof Geofence._instance === 'undefined') {
Geofence._instance = new Geofence();
}
return Geofence._instance;
}
isGeofenceRegisteredByUuid(id) {
return this._fillGeofencesRegisteredIfNotExists()
.then(() => {
return (id in this.geofencesRegistered);
});
}
getGeofences() {
return new Promise((resolve, reject) => {
window.BackgroundGeolocation.getGeofences((geofences) => {
// Each one: console.log("Geofence: ", geofence.identifier, geofence.radius, geofence.latitude,
// geofence.longitude);
resolve(geofences);
}, (err) => {
console.log(`Failed to fetch geofences from server: ${err.message}`);
reject(err);
});
});
}
addRegionIfNotExists(region) {
console.log('addRegionIfNotExists called');
return new Promise((resolve, reject) => {
this.isGeofenceRegisteredByUuid(region.identifier)
.then((registered) => {
if (registered) {
return new Promise(); // just to be consistent for eslint, otherwise return is just fine
} else {
return this._addRegion(region);
}
})
.then(() => {
resolve(); // done
})
.catch((err) => {
reject(err);
});
});
}
removeById(id) {
return new Promise((resolve, reject) => {
let bgGeo = window.BackgroundGeolocation;
bgGeo.removeGeofence(id, () => {
console.log('Geofence.remove successful for id:' + id);
resolve();
}, (err) => {
console.log('Geofence.remove error: ' + JSON.stringify(err));
reject(err);
});
});
}
removeAllGeofences() {
return new Promise((resolve, reject) => {
BackgroundGeolocation.removeGeofences(() => {
console.log("Successfully removed alll geofences");
resolve();
}, (error) => {
console.warn("Failed to remove geofence", error);
reject();
});
});
}
_addRegion(region) {
new Promise((resolve, reject) => {
window.BackgroundGeolocation.addGeofences([region], () => {
console.log('Add geofence-lt success');
resolve();
}, (err) => {
console.log('Add geofence-lt failure:' + err.message);
reject(err);
});
});
}
registerAddedRegions() {
}
start() {
return new Promise((resolve, reject) => {
window.BackgroundGeolocation.startGeofences((state) => {
console.log('Geofence-only monitoring started', state.trackingMode);
resolve();
});
});
}
// This doesn't just stop geofences, this stop all activities tracking
stop() {
return new Promise((resolve, reject) => {
window.BackgroundGeolocation.stop(() => {
console.log('Geofence stopped.');
resolve();
}, (err) => {
console.log(`Geofence.stop error: ${err.message}`);
reject(err);
});
});
}
_setup() {
this._bind();
console.log('window.BackgroundGeolocation.configure run');
window.BackgroundGeolocation.configure({
desiredAccuracy: 1000, // <-- Config params // 0, 10, 100, 1000, where 1000 is the lowest accuracy
distanceFilter: 50,
timeout: 40000, // 40 seconds for every location fetch
activityRecognitionInterval: 10000, // android
// locationUpdateInterval: 1000,// With distanceFilter: 0, Sets the desired interval for location updates, in milliseconds.
timeout: 3000,
geofenceInitialTriggerEntry: true,
fastestLocationUpdateInterval: 10000,
forceReloadOnGeofence: true,
foregroundService: true,
}, (state) => { // <-- Current state provided to #configure callback
console.log('BackgroundGeolocation is configured and ready to use. State:' + JSON.stringify(state));
/*
if (!state.enabled) {
} else {
}
*/
}, (err) => {
console.log(`Background Geolocation failed to configure: ${err.message}`);
});
}
_bind() {
window.BackgroundGeolocation.on('geofence', (evt) => { // for crossing events
//
// {"location":{"event":"geofence","is_moving":false,"uuid":"3a81721f-7116-4cc9-b53c-88d4ca884399",
// "timestamp":"2017-12-13T06:57:35.805Z","odometer":0,
// "coords":{"latitude":25.0536594,"longitude":121.5996323,"accuracy":5.3,"speed":-1,"heading":-1,"altitude":-1},
// "activity":{"type":"still","confidence":100},"battery":{"is_charging":true,"level":0.95},
// "geofence":{"identifier":"3b450b2418325db2fb7e9eddf96d6f3a","action":"EXIT"},
// "extras":{}},"identifier":"3b450b2418325db2fb7e9eddf96d6f3a","action":"EXIT"}"
console.log('geofence crossing event received:' + JSON.stringify(evt));
// Make it to look like format of an older plugin:
let obj = {};
obj.latitude = evt.location.coords.latitude;
obj.longitude = evt.location.coords.longitude;
obj.radius = 200;
obj.id = evt.location.uuid; // or is it identifier?
obj.transitionType = (evt.location.geofence.action === 'EXIT') ? 2 : 1; // CLRegionStateInside 1, CLRegionStateOutside 2
this.emit('regionTransition', [obj]);
});
}
_fillGeofencesRegisteredIfNotExists() {
return new Promise((resolve, reject) => {
if (this.geofencesRegistered) {
resolve();
} else {
this.getGeofences()
.then((geofences) => {
this.geofencesRegistered = {};
for (const geofence of geofences) {
this.geofencesRegistered[geofence.uuid] = geofence;
}
})
.then(() => {
resolve();
})
.catch((err) => {
console.log(`_fillGeofencesRegistered error: ${err.message}`);
reject(err);
});
}
});
}
}
// export { Geofence };
Btw, as of 2.11.0
, the plugin's API already uses promises. For example, see getGeofences
. Notice how just about every API method return new Promise(...)
.
As for your issue, you've not configured stopOnTerminate: false
(the default is true
). Therefore, every time you terminate the app, the plugin stops, thus enabled: false
every time you boot.
Does this has to do with the license key? It is enabled: false
still.
enabled: false
is now the culprit for no geofence me but I don't know if that is really the case. My Galaxy S9 never can get the "location service activated" notification every time I build a production release. And every time I don't get that, geofence doesn't work.
Also my console shows two license keys of the same app id. I must have pressed again before the first one can be entered. I don't know if this has anything to do with it. When does the license key gets verified? Is it during compilation?
Show me $ adb logcat
of your app booting.
When does the license key gets verified? Is it during compilation?
The plugin knows nothing of the Product Dashboard. The plugin does not authenticate with a server. Authentication occurs within encrypted library code at run time. The plugin reads your LICENSE
from the AndroidManifest.xml
When sending me logs, always configure logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE
.
Verbose was on, hopefully.
I see nothing interesting.
#stop
the plugin.#start
the pluginYou got me thinking about the whole thing. I think I'm onto the wrong thing.
If I don't use stopOnTerminate: false
then I don't need to call stop right? Our original use case is only to make sure it runs when the app is in the task list.
Currently, this is my use case:
User open the apps. Put the app in the background. Now the app will register the geofence if it hasn't done so already. And a notification that says Location service activated
should be received (because foregroundService
is set to true
).
If I am only using geofence and not other type of tracking. I only need to call startGeofences
and not start
right? And I don't need to stop if my stopOnTerminate
is true (as by default)?
But now I don't see that notification. And everytime I don't see the notification, so far when I take the time to test it in the wild, it doesn't seem to work on Galaxy S9. So now I just want to see that notification first.
Here is the log where I don't set stopOnTerminate
to false
. I start the app. Put it in the background. And wait to see that notification, but it doens't come up.
I think you are importing an insufficient version of appcompat-v7
. Paste your platforms/android/project.properties
target=android-26
android.library.reference.1=CordovaLib
cordova.gradle.include.1=cordova-android-support-gradle-release/brilonglock-cordova-android-support-gradle-release.gradle
cordova.gradle.include.2=cordova-plugin-background-fetch/brilonglock-build.gradle
cordova.system.library.1=com.google.android.gms:play-services-location:11.8.0
cordova.system.library.2=com.android.support:appcompat-v7:27.0.0
cordova.gradle.include.3=cordova-background-geolocation-lt/brilonglock-build.gradle
cordova.gradle.include.4=cordova-plugin-badge/brilonglock-badge.gradle
cordova.gradle.include.5=cordova-plugin-bluenet-dfu/brilonglock-build-extras.gradle
cordova.gradle.include.6=cordova-plugin-buildinfo/brilonglock-BuildInfo.gradle
cordova.system.library.3=com.android.support:support-v4:27.0.0
cordova.system.library.4=com.android.support:support-v4:27.0.0
cordova.gradle.include.7=cordova-plugin-local-notification/brilonglock-localnotification.gradle
cordova.gradle.include.8=phonegap-plugin-barcodescanner/brilonglock-barcodescanner.gradle
cordova.system.library.5=com.android.support:support-v4:27.0.0
cordova.system.library.6=com.android.support:support-v13:26.+
cordova.system.library.7=me.leolin:ShortcutBadger:1.1.17@aar
cordova.system.library.8=com.google.firebase:firebase-messaging:11.8.0
cordova.gradle.include.9=phonegap-plugin-push/brilonglock-push.gradlea
Any clues? The weird thing is I can get it work without a license key.
Obviously this an issue:
cordova.system.library.6=com.android.support:support-v13:26.+
Since every other support lib is importing 27.0.0
Hmm..somehow that creeps in.
Here is a build which does not have that issue. I ran the app with the same procedure. But I still don't get that notification.
It seems like callback to window.BackgroundGeolocation.startGeofences()
doesn't get called. (Same code as I pasted already above.)
Attached is the log.
And project.properties pasted here:
target=android-26 android.library.reference.1=CordovaLib cordova.gradle.include.1=cordova-plugin-badge/brilonglock-badge.gradle cordova.system.library.1=com.android.support:support-v4:27.0.0 cordova.system.library.2=com.google.gms:google-services:3.2.1 cordova.gradle.include.2=cordova-plugin-bluenet-dfu/brilonglock-build-extras.gradle cordova.gradle.include.3=cordova-plugin-buildinfo/brilonglock-BuildInfo.gradle cordova.gradle.include.4=cordova-plugin-firebase/brilonglock-build.gradle cordova.gradle.include.5=cordova-plugin-local-notification/brilonglock-localnotification.gradle cordova.system.library.3=com.google.android.gms:play-services-tagmanager:11.8.0 cordova.gradle.include.6=phonegap-plugin-barcodescanner/brilonglock-barcodescanner.gradle cordova.system.library.4=com.google.firebase:firebase-core:11.8.0 cordova.system.library.5=com.google.firebase:firebase-messaging:11.8.0 cordova.system.library.6=com.google.firebase:firebase-crash:11.8.0 cordova.system.library.7=com.google.firebase:firebase-config:11.8.0 cordova.system.library.8=com.android.support:support-v4:27.0.0 cordova.gradle.include.7=cordova-android-support-gradle-release/brilonglock-cordova-android-support-gradle-release.gradle cordova.gradle.include.8=cordova-plugin-background-fetch/brilonglock-build.gradle cordova.system.library.9=com.google.android.gms:play-services-location:11.8.0 cordova.system.library.10=com.android.support:appcompat-v7:27.0.0 cordova.gradle.include.9=cordova-background-geolocation-lt/brilonglock-build.gradle
The title of this issue is "Enabled is false after configure". Is this not solved?
Maybe I should have create a new issue? I don't know think that is what I want. Like I said in this chain of discussion, my main issue is that there is no Geofence event because service doesn't seem to be run. (No notification when app is in the background on Android 8.) And enabled is false doesn't seem relevant because stopOnTerminate: false
doesn't appear to be what I need. I just need geofence event to trigger when it's in the list of apps running.
I do not see in your logs that you're using LOG_LEVEL_VERBOSE
.
That's weird I thought I turned it on.
Here I tried it again the result of adb logcat
. I made sure via console.log that callback to setLogLevel was ran. (Though any line with INFO:CONSOLE is removed manually afterward).
Here it is: LogOnLaunch5.txt
Here is project.property just to make sure things have not been changed.
target=android-26
android.library.reference.1=CordovaLib
cordova.gradle.include.1=cordova-plugin-badge/brilonglock-badge.gradle
cordova.system.library.1=com.android.support:support-v4:27.0.0
cordova.system.library.2=com.google.gms:google-services:3.2.1
cordova.gradle.include.2=cordova-plugin-bluenet-dfu/brilonglock-build-extras.gradle
cordova.gradle.include.3=cordova-plugin-buildinfo/brilonglock-BuildInfo.gradle
cordova.gradle.include.4=cordova-plugin-firebase/brilonglock-build.gradle
cordova.gradle.include.5=cordova-plugin-local-notification/brilonglock-localnotification.gradle
cordova.system.library.3=com.google.android.gms:play-services-tagmanager:11.8.0
cordova.gradle.include.6=phonegap-plugin-barcodescanner/brilonglock-barcodescanner.gradle
cordova.system.library.4=com.google.firebase:firebase-core:11.8.0
cordova.system.library.5=com.google.firebase:firebase-messaging:11.8.0
cordova.system.library.6=com.google.firebase:firebase-crash:11.8.0
cordova.system.library.7=com.google.firebase:firebase-config:11.8.0
cordova.system.library.8=com.android.support:support-v4:27.0.0
cordova.gradle.include.7=cordova-android-support-gradle-release/brilonglock-cordova-android-support-gradle-release.gradle
cordova.gradle.include.8=cordova-plugin-background-fetch/brilonglock-build.gradle
cordova.system.library.9=com.google.android.gms:play-services-location:11.8.0
cordova.system.library.10=com.android.support:appcompat-v7:27.0.0
cordova.gradle.include.9=cordova-background-geolocation-lt/brilonglock-build.gradle
Any pointers?
No idea:
#stop
plugin.#start
plugin.show me those logs.
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-26
android.library.reference.1=CordovaLib
cordova.gradle.include.1=cordova-plugin-badge/brilonglock-badge.gradle
cordova.system.library.1=com.android.support:support-v4:27.0.0
cordova.system.library.2=com.google.gms:google-services:3.2.1
cordova.gradle.include.2=cordova-plugin-bluenet-dfu/brilonglock-build-extras.gradle
cordova.gradle.include.3=cordova-plugin-buildinfo/brilonglock-BuildInfo.gradle
cordova.gradle.include.4=cordova-plugin-firebase/brilonglock-build.gradle
cordova.gradle.include.5=cordova-plugin-local-notification/brilonglock-localnotification.gradle
cordova.system.library.3=com.google.android.gms:play-services-tagmanager:11.8.0
cordova.gradle.include.6=phonegap-plugin-barcodescanner/brilonglock-barcodescanner.gradle
cordova.system.library.4=com.google.firebase:firebase-core:11.8.0
cordova.system.library.5=com.google.firebase:firebase-messaging:11.8.0
cordova.system.library.6=com.google.firebase:firebase-crash:11.8.0
cordova.system.library.7=com.google.firebase:firebase-config:11.8.0
cordova.system.library.8=com.android.support:support-v4:27.0.0
cordova.gradle.include.7=cordova-android-support-gradle-release/brilonglock-cordova-android-support-gradle-release.gradle
cordova.gradle.include.8=cordova-plugin-background-fetch/brilonglock-build.gradle
cordova.system.library.9=com.google.android.gms:play-services-location:11.8.0
cordova.system.library.10=com.android.support:appcompat-v7:27.0.0
cordova.gradle.include.9=cordova-background-geolocation-lt/brilonglock-build.gradle
Are you building for DEBUG or RELEASE?
If I recall correctly the above is from debug. I think it may be some sort of timing issue, right now it also doesn't work when building for debug.
Hi Chris, any clue to this one?
Can you zip your project and email it to me? I'll build it locally and see for myself.
chris@transistorsoft.com
Your Environment
cordova -v
): 7.1.0cordova platform ls
): android 6.4.0Plugin config
window.BackgroundGeolocation.configure({ desiredAccuracy: 1000, // <-- Config params // 0, 10, 100, 1000, where 1000 is the lowest accuracy distanceFilter: 50, timeout: 40000, // 40 seconds for every location fetch activityRecognitionInterval: 10000, // android // locationUpdateInterval: 1000,// With distanceFilter: 0, Sets the desired interval for location updates, in milliseconds. timeout: 3000, geofenceInitialTriggerEntry: true, fastestLocationUpdateInterval: 10000, forceReloadOnGeofence: true, foregroundService: true }, function(state) { //state.enabled is false here });
Expected Behavior
Expect state.enabled to be true. N
Actual Behavior
state.enabled to be false.
Steps to Reproduce
Context
Geofence. And your example shows that I should start geofence when state.enabled is true.
Debug logs
Not sure what to show here..
Here is
platforms/android/project.properties