@azatek/background-geolocation 1.0.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -42,7 +42,8 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
|
|
42
42
|
@Permission(
|
|
43
43
|
strings = {
|
|
44
44
|
Manifest.permission.ACCESS_COARSE_LOCATION,
|
|
45
|
-
Manifest.permission.ACCESS_FINE_LOCATION
|
|
45
|
+
Manifest.permission.ACCESS_FINE_LOCATION,
|
|
46
|
+
Manifest.permission.FOREGROUND_SERVICE_LOCATION
|
|
46
47
|
},
|
|
47
48
|
alias = "location"
|
|
48
49
|
)
|
|
@@ -70,23 +71,12 @@ public class BackgroundGeolocation extends Plugin {
|
|
|
70
71
|
} catch (SecurityException ignore) {}
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
call.reject("Service not running.");
|
|
74
|
+
private void startWatcher(PluginCall call) {
|
|
75
|
+
if (!isLocationEnabled(getContext())) {
|
|
76
|
+
call.reject("Location services disabled.", "NOT_AUTHORIZED");
|
|
77
77
|
return;
|
|
78
78
|
}
|
|
79
|
-
call.setKeepAlive(true);
|
|
80
79
|
|
|
81
|
-
if (getPermissionState("location") != PermissionState.GRANTED) {
|
|
82
|
-
if (call.getBoolean("requestPermissions", true)) {
|
|
83
|
-
requestPermissionForAlias("location", call, "locationPermissionsCallback");
|
|
84
|
-
} else {
|
|
85
|
-
call.reject("Permission denied.", "NOT_AUTHORIZED");
|
|
86
|
-
}
|
|
87
|
-
} else if (!isLocationEnabled(getContext())) {
|
|
88
|
-
call.reject("Location services disabled.", "NOT_AUTHORIZED");
|
|
89
|
-
}
|
|
90
80
|
if (call.getBoolean("stale", false)) {
|
|
91
81
|
fetchLastLocation(call);
|
|
92
82
|
}
|
|
@@ -164,6 +154,26 @@ public class BackgroundGeolocation extends Plugin {
|
|
|
164
154
|
);
|
|
165
155
|
}
|
|
166
156
|
|
|
157
|
+
@PluginMethod(returnType = PluginMethod.RETURN_CALLBACK)
|
|
158
|
+
public void addWatcher(final PluginCall call) {
|
|
159
|
+
if (service == null) {
|
|
160
|
+
call.reject("Service not running.");
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
call.setKeepAlive(true);
|
|
164
|
+
|
|
165
|
+
if (getPermissionState("location") != PermissionState.GRANTED) {
|
|
166
|
+
if (call.getBoolean("requestPermissions", true)) {
|
|
167
|
+
requestPermissionForAlias("location", call, "locationPermissionsCallback");
|
|
168
|
+
} else {
|
|
169
|
+
call.reject("Permission denied.", "NOT_AUTHORIZED");
|
|
170
|
+
}
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
startWatcher(call);
|
|
175
|
+
}
|
|
176
|
+
|
|
167
177
|
@PermissionCallback
|
|
168
178
|
private void locationPermissionsCallback(PluginCall call) {
|
|
169
179
|
|
|
@@ -171,15 +181,13 @@ public class BackgroundGeolocation extends Plugin {
|
|
|
171
181
|
call.reject("User denied location permission", "NOT_AUTHORIZED");
|
|
172
182
|
return;
|
|
173
183
|
}
|
|
174
|
-
|
|
175
|
-
fetchLastLocation(call);
|
|
176
|
-
}
|
|
184
|
+
|
|
177
185
|
if (service != null) {
|
|
178
186
|
service.onPermissionsGranted();
|
|
179
|
-
// The handleOnResume method will now be called, and we don't need it to call
|
|
180
|
-
// service.onPermissionsGranted again so we reset this flag.
|
|
181
187
|
stoppedWithoutPermissions = false;
|
|
182
188
|
}
|
|
189
|
+
|
|
190
|
+
startWatcher(call);
|
|
183
191
|
}
|
|
184
192
|
|
|
185
193
|
@PluginMethod()
|
|
@@ -16,6 +16,7 @@ import com.google.android.gms.location.LocationCallback;
|
|
|
16
16
|
import com.google.android.gms.location.LocationRequest;
|
|
17
17
|
import com.google.android.gms.location.LocationResult;
|
|
18
18
|
import com.google.android.gms.location.LocationServices;
|
|
19
|
+
import com.google.android.gms.location.Priority;
|
|
19
20
|
|
|
20
21
|
import java.util.HashSet;
|
|
21
22
|
|
|
@@ -118,7 +119,11 @@ public class BackgroundGeolocationService extends Service {
|
|
|
118
119
|
LocationCallback callback = new LocationCallback(){
|
|
119
120
|
@Override
|
|
120
121
|
public void onLocationResult(LocationResult locationResult) {
|
|
122
|
+
Logger.debug("onLocationResult called");
|
|
121
123
|
Location location = locationResult.getLastLocation();
|
|
124
|
+
if (location != null) {
|
|
125
|
+
Logger.debug("Location received: " + location.getLatitude() + ", " + location.getLongitude());
|
|
126
|
+
}
|
|
122
127
|
Intent intent = new Intent(ACTION_BROADCAST);
|
|
123
128
|
intent.putExtra("location", location);
|
|
124
129
|
intent.putExtra("id", id);
|
|
@@ -128,6 +133,7 @@ public class BackgroundGeolocationService extends Service {
|
|
|
128
133
|
}
|
|
129
134
|
@Override
|
|
130
135
|
public void onLocationAvailability(LocationAvailability availability) {
|
|
136
|
+
Logger.debug("Location availability: " + availability.isLocationAvailable());
|
|
131
137
|
if (!availability.isLocationAvailable()) {
|
|
132
138
|
Logger.debug("Location not available");
|
|
133
139
|
}
|
|
@@ -146,12 +152,16 @@ public class BackgroundGeolocationService extends Service {
|
|
|
146
152
|
// permissions are not yet granted. Rather than check the permissions, which is fiddly,
|
|
147
153
|
// we simply ignore the exception.
|
|
148
154
|
try {
|
|
155
|
+
Logger.debug("Requesting location updates with priority: " + priority + ", interval: " + interval);
|
|
149
156
|
watcher.client.requestLocationUpdates(
|
|
150
157
|
watcher.locationRequest,
|
|
151
158
|
watcher.locationCallback,
|
|
152
159
|
null
|
|
153
160
|
);
|
|
154
|
-
|
|
161
|
+
Logger.debug("Location updates requested successfully");
|
|
162
|
+
} catch (SecurityException e) {
|
|
163
|
+
Logger.error("SecurityException when requesting location updates", e);
|
|
164
|
+
}
|
|
155
165
|
|
|
156
166
|
// Promote the service to the foreground if necessary.
|
|
157
167
|
// Ideally we would only call 'startForeground' if the service is not already
|
package/index.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azatek/background-geolocation",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "Capacitor plugin for background geolocation tracking with configurable GPS accuracy modes (HIGH/BALANCED/LOW/PASSIVE) for battery optimization. Fork of @capacitor-community/background-geolocation with enhanced accuracy control.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"capacitor",
|
|
@@ -21,8 +21,18 @@
|
|
|
21
21
|
},
|
|
22
22
|
"author": "AzaTek",
|
|
23
23
|
"license": "MIT",
|
|
24
|
+
"main": "index.js",
|
|
25
|
+
"module": "index.js",
|
|
24
26
|
"types": "definitions.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./definitions.d.ts",
|
|
30
|
+
"import": "./index.js",
|
|
31
|
+
"require": "./index.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
25
34
|
"files": [
|
|
35
|
+
"index.js",
|
|
26
36
|
"CapacitorCommunityBackgroundGeolocation.podspec",
|
|
27
37
|
"Package.swift",
|
|
28
38
|
"android/build.gradle",
|