Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geofence notification fixes #314

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
77a2e32
[new]-geofence plugin changes
sowmya-kiot Dec 31, 2021
1bffb30
[fix]- plugin xml fix
sowmya-kiot Dec 31, 2021
28c6dbb
[new]- geo transition api calls
sowmya-kiot Jan 4, 2022
90a39e3
[new]- api callback function
sowmya-kiot Jan 5, 2022
2163371
[update] removed ios support
chaymankala Jan 27, 2022
2a8ed06
[fix] gson issue
chaymankala Jan 27, 2022
39b19b0
[update] id
chaymankala Jan 27, 2022
7996480
[update] base url moved to prefs
chaymankala Jan 27, 2022
4a7ca41
[new]- add geofence error fix
sowmya-kiot Feb 8, 2022
46789d2
[fix]- notification change after api call
sowmya-kiot Feb 8, 2022
f6b543b
Update AbstractGoogleServiceCommand.java
sowmya-kiot Apr 6, 2022
9e58b39
Update AddGeofenceCommand.java
sowmya-kiot Apr 6, 2022
f2eb8c7
Update AssetUtil.java
sowmya-kiot Apr 6, 2022
f2f794e
Update BeepHelper.java
sowmya-kiot Apr 6, 2022
d834e5e
Update CommandExecutionHandler.java
sowmya-kiot Apr 6, 2022
13ef52b
Create GeofenceBroadcastReceiver.java
sowmya-kiot Apr 6, 2022
94aacce
Create GeofenceErrorMessages.java
sowmya-kiot Apr 6, 2022
2f35418
Update GeofencePlugin.java
sowmya-kiot Apr 6, 2022
b250db1
Create GeofenceTransitionsJobIntentService.java
sowmya-kiot Apr 6, 2022
2a94993
Update GeoNotification.java
sowmya-kiot Apr 6, 2022
d97a6f1
Update GeoNotificationManager.java
sowmya-kiot Apr 6, 2022
4eb9989
Update GeoNotificationNotifier.java
sowmya-kiot Apr 6, 2022
c949734
Update GeoNotificationStore.java
sowmya-kiot Apr 6, 2022
6e0cf92
Update GoogleServiceCommandExecutor.java
sowmya-kiot Apr 6, 2022
1f544aa
Update Gson.java
sowmya-kiot Apr 6, 2022
01781cc
Update IGoogleServiceCommandListener.java
sowmya-kiot Apr 6, 2022
d9a8b57
Update LocalStorage.java
sowmya-kiot Apr 6, 2022
39f962c
Update LocalStorageDBHelper.java
sowmya-kiot Apr 6, 2022
3f039eb
Update Logger.java
sowmya-kiot Apr 6, 2022
d4f9d07
Update Notification.java
sowmya-kiot Apr 6, 2022
7e667fb
Update Notification.java
sowmya-kiot Apr 6, 2022
3480c76
Update ReceiveTransitionsIntentService.java
sowmya-kiot Apr 6, 2022
92bde51
Update RemoveGeofenceCommand.java
sowmya-kiot Apr 6, 2022
9501dcd
Update VolleyApi.java
sowmya-kiot Apr 6, 2022
9f039cd
Update VolleyCallback.java
sowmya-kiot Apr 6, 2022
31dac41
[fix]- minor changes to plugin
sowmya-kiot Apr 6, 2022
a52bd2a
Merge pull request #1 from Kiot-innovations-pvt/plugin-new-changes
sowmya-kiot Apr 6, 2022
a6be6cc
[fix]-notification fix
sowmya-kiot Apr 7, 2022
6fedbd9
[fix] dont use .event
chaymankala Apr 14, 2022
bd95ead
[fix]- notification issue fixes
sowmya-kiot May 18, 2022
775bdc1
[chore] removed comments
chaymankala May 19, 2022
2bf8cea
[update] new release
chaymankala May 19, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16,416 changes: 16,416 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "cordova-plugin-geofence",
"version": "0.7.0",
"name": "kiot-cordova-plugin-geofence",
"version": "1.0.2",
"description": "Cordova geofence plugin",
"cordova": {
"id": "cordova-plugin-geofence",
"id": "kiot-cordova-plugin-geofence",
"platforms": [
"android",
"ios",
Expand All @@ -20,7 +20,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/cowbell/cordova-plugin-geofence.git"
"url": "git+https://github.com/Kiot-innovations-pvt/cordova-plugin-geofence.git"
},
"keywords": [
"cordova",
Expand All @@ -33,12 +33,12 @@
"cordova-windows8",
"cordova-windows"
],
"author": "Cowbell Labs",
"author": "Kiot Innovations",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/cowbell/cordova-plugin-geofence/issues"
"url": "https://github.com/Kiot-innovations-pvt/cordova-plugin-geofence/issues"
},
"homepage": "https://github.com/cowbell/cordova-plugin-geofence#readme",
"homepage": "https://github.com/Kiot-innovations-pvt/cordova-plugin-geofence#readme",
"engines": [
{
"name": "cordova",
Expand Down
59 changes: 21 additions & 38 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>

<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0" xmlns:m2="http://schemas.microsoft.com/appx/2013/manifest" xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-geofence" version="0.7.0">
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0" xmlns:m2="http://schemas.microsoft.com/appx/2013/manifest" xmlns:android="http://schemas.android.com/apk/res/android" id="kiot-cordova-plugin-geofence" version="0.7.0">
<name>geofence</name>
<description>Geofence plugin</description>
<license>Apache 2.0</license>
<keywords>phonegap,background geolocation, geofence</keywords>
<repo>https://github.com/cowbell/cordova-plugin-geofence.git</repo>
<issue>https://github.com/cowbell/cordova-plugin-geofence/issues</issue>
<repo>https://github.com/Kiot-innovations-pvt/cordova-plugin-geofence.git</repo>
<issue>https://github.com/Kiot-innovations-pvt/cordova-plugin-geofence/issues</issue>
<engines>
<engine name="cordova" version=">=5.0.0" />
</engines>
Expand All @@ -19,10 +19,10 @@
<clobbers target="geofence" />
</js-module>

<dependency id="cordova-plugin-add-swift-support" version="1.6.0" />
<dependency id="cordova-plugin-compat" version="^1.0.0" />
<dependency id="es6-promise-plugin" />


<!-- android -->
<platform name="android">
<source-file src="src/android/AbstractGoogleServiceCommand.java" target-dir="src/com/cowbell/cordova/geofence" />
Expand All @@ -45,9 +45,16 @@
<source-file src="src/android/Notification.java" target-dir="src/com/cowbell/cordova/geofence" />
<source-file src="src/android/ReceiveTransitionsIntentService.java" target-dir="src/com/cowbell/cordova/geofence" />
<source-file src="src/android/RemoveGeofenceCommand.java" target-dir="src/com/cowbell/cordova/geofence" />
<source-file src="src/android/VolleyApi.java" target-dir="src/com/cowbell/cordova/geofence" />
<source-file src="src/android/VolleyCallback.java" target-dir="src/com/cowbell/cordova/geofence" />
<source-file src="src/android/GeofenceTransitionsJobIntentService.java" target-dir="src/com/cowbell/cordova/geofence" />
<source-file src="src/android/GeofenceBroadcastReceiver.java" target-dir="src/com/cowbell/cordova/geofence" />
<source-file src="src/android/GeofenceErrorMessages.java" target-dir="src/com/cowbell/cordova/geofence" />

<framework src="com.google.android.gms:play-services-location:+" />
<lib-file src="src/android/libs/gson-2.3.jar" />
<framework src="com.android.volley:volley:1.2.1" />
<framework src="com.google.code.gson:gson:2.8.5" />
<!-- <lib-file src="src/android/libs/gson-2.8.5.jar" /> -->

<config-file target="config.xml" parent="/*">
<feature name="GeofencePlugin">
Expand All @@ -56,8 +63,10 @@
</config-file>

<config-file target="AndroidManifest.xml" parent="/manifest/application">
<service android:name="com.cowbell.cordova.geofence.ReceiveTransitionsIntentService" android:label="@string/app_name" android:exported="false">
</service>
<service
android:name="com.cowbell.cordova.geofence.GeofenceTransitionsJobIntentService"
android:exported="true"
android:permission="android.permission.BIND_JOB_SERVICE" />
</config-file>

<config-file target="AndroidManifest.xml" parent="/manifest/application">
Expand All @@ -66,12 +75,17 @@
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<receiver
android:name="com.cowbell.cordova.geofence.GeofenceBroadcastReceiver"
android:enabled="true"
android:exported="true" />
</config-file>

<config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.VIBRATE" />
</config-file>

Expand Down Expand Up @@ -109,35 +123,4 @@
<runs />
</js-module>
</platform>

<!-- ios -->
<platform name="ios">
<preference name="GEOFENCE_ALWAYS_USAGE_DESCRIPTION" default="${EXECUTABLE_NAME} Would Like to Use Your Current Location Even In Background." />
<config-file target="*-Info.plist" parent="NSLocationAlwaysUsageDescription">
<string>$GEOFENCE_ALWAYS_USAGE_DESCRIPTION</string>
</config-file>

<preference name="GEOFENCE_IN_USE_USAGE_DESCRIPTION" default="${EXECUTABLE_NAME} Would Like to Use Your Current Location When In Use." />
<config-file target="*-Info.plist" parent="NSLocationWhenInUseUsageDescription">
<string>$GEOFENCE_IN_USE_USAGE_DESCRIPTION</string>
</config-file>


<config-file target="*-Info.plist" parent="UIBackgroundModes">
<array>
<string>remote-notification</string>
</array>
</config-file>
<config-file target="config.xml" parent="/*">
<feature name="GeofencePlugin">
<param name="ios-package" value="HWPGeofencePlugin"/>
</feature>
</config-file>
<header-file src="src/ios/Geofence-Plugin-Bridging-Header.h" />
<source-file src="src/ios/GeofencePlugin.swift"/>
<source-file src="src/ios/SwiftData.swift"/>
<source-file src="src/ios/SwiftyJson.swift"/>
<framework src="libsqlite3.dylib"/>
<framework src="WebKit.framework" weak="true" />
</platform>
</plugin>
10 changes: 5 additions & 5 deletions src/android/AbstractGoogleServiceCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ public abstract class AbstractGoogleServiceCommand implements
public AbstractGoogleServiceCommand(Context context) {
this.context = context;
mGoogleApiClient = new GoogleApiClient.Builder(context)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
logger = Logger.getLogger();
listeners = new ArrayList<IGoogleServiceCommandListener>();
}

private void connectToGoogleServices() {
if (!mGoogleApiClient.isConnected() ||
(!mGoogleApiClient.isConnecting() && !connectionInProgress)) {
(!mGoogleApiClient.isConnecting() && !connectionInProgress)) {
connectionInProgress = true;
logger.log(Log.DEBUG, "Connecting location client");
mGoogleApiClient.connect();
Expand Down
66 changes: 35 additions & 31 deletions src/android/AddGeofenceCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import com.google.android.gms.common.api.Status;
import com.google.android.gms.location.Geofence;
import com.google.android.gms.location.GeofenceStatusCodes;
import com.google.android.gms.location.GeofencingRequest;
import com.google.android.gms.location.LocationServices;

import org.apache.cordova.LOG;
//import org.apache.cordova.LOG;
import org.json.JSONException;
import org.json.JSONObject;

Expand All @@ -21,53 +22,56 @@
public class AddGeofenceCommand extends AbstractGoogleServiceCommand {
private List<Geofence> geofencesToAdd;
private PendingIntent pendingIntent;
private GeofencingRequest geofencingRequest;

public AddGeofenceCommand(Context context, PendingIntent pendingIntent,
public AddGeofenceCommand(Context context, GeofencingRequest geofencingRequest, PendingIntent pendingIntent,
List<Geofence> geofencesToAdd) {
super(context);
this.geofencesToAdd = geofencesToAdd;
this.pendingIntent = pendingIntent;
this.geofencingRequest = geofencingRequest;
}

@Override
public void ExecuteCustomCode() {
logger.log(Log.DEBUG, "Adding new geofences...");
if (geofencesToAdd != null && geofencesToAdd.size() > 0) try {
//mGeofencingClient.addGeofences(geofencingRequest, pendingIntent);
LocationServices.GeofencingApi
.addGeofences(mGoogleApiClient, geofencesToAdd, pendingIntent)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
logger.log(Log.DEBUG, "Geofences successfully added");
CommandExecuted();
} else try {
Map<Integer, String> errorCodeMap = new HashMap<Integer, String>();
errorCodeMap.put(GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE, GeofencePlugin.ERROR_GEOFENCE_NOT_AVAILABLE);
errorCodeMap.put(GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES, GeofencePlugin.ERROR_GEOFENCE_LIMIT_EXCEEDED);
.addGeofences(mGoogleApiClient, geofencesToAdd, pendingIntent)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
logger.log(Log.DEBUG, "Geofences successfully added");
CommandExecuted();
} else try {
Map<Integer, String> errorCodeMap = new HashMap<Integer, String>();
errorCodeMap.put(GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE, GeofencePlugin.ERROR_GEOFENCE_NOT_AVAILABLE);
errorCodeMap.put(GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES, GeofencePlugin.ERROR_GEOFENCE_LIMIT_EXCEEDED);

Integer statusCode = status.getStatusCode();
String message = "Adding geofences failed - SystemCode: " + statusCode;
JSONObject error = new JSONObject();
error.put("message", message);
Integer statusCode = status.getStatusCode();
String message = "Adding geofences failed - SystemCode: " + statusCode;
JSONObject error = new JSONObject();
error.put("message", message);

if (statusCode == GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE) {
error.put("code", GeofencePlugin.ERROR_GEOFENCE_NOT_AVAILABLE);
} else if (statusCode == GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES) {
error.put("code", GeofencePlugin.ERROR_GEOFENCE_LIMIT_EXCEEDED);
} else {
error.put("code", GeofencePlugin.ERROR_UNKNOWN);
}
if (statusCode == GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE) {
error.put("code", GeofencePlugin.ERROR_GEOFENCE_NOT_AVAILABLE);
} else if (statusCode == GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES) {
error.put("code", GeofencePlugin.ERROR_GEOFENCE_LIMIT_EXCEEDED);
} else {
error.put("code", GeofencePlugin.ERROR_UNKNOWN);
}

logger.log(Log.ERROR, message);
CommandExecuted(error);
} catch (JSONException exception) {
CommandExecuted(exception);
logger.log(Log.ERROR, message);
CommandExecuted(error);
} catch (JSONException exception) {
CommandExecuted(exception);
}
}
}
});
});
} catch (Exception exception) {
logger.log(LOG.ERROR, "Exception while adding geofences");
logger.log(2, "Exception while adding geofences");
exception.printStackTrace();
CommandExecuted(exception);
}
Expand Down
4 changes: 2 additions & 2 deletions src/android/BeepHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public BeepHelper() {
}

/**
* Plays debug sound
*
* Plays debug sounda
*
* @param name
*/
public void startTone(String name) {
Expand Down
42 changes: 35 additions & 7 deletions src/android/GeoNotification.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
package com.cowbell.cordova.geofence;

import com.google.android.gms.location.Geofence;
import com.google.android.gms.location.GeofencingClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.android.gms.location.GeofencingRequest;
import com.google.gson.annotations.Expose;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class GeoNotification {
@Expose public String _id;
@Expose public String id;
@Expose public String name;
@Expose public String event;
@Expose public String home_id;
@Expose public String user_id;
@Expose public String w_actions;
@Expose public double latitude;
@Expose public double longitude;
@Expose public int radius;
Expand All @@ -16,19 +33,30 @@ public GeoNotification() {
}

public Geofence toGeofence() {
return new Geofence.Builder()
.setRequestId(id)
.setTransitionTypes(transitionType)
.setCircularRegion(latitude, longitude, radius)
.setExpirationDuration(Long.MAX_VALUE).build();
if(transitionType == 1 || transitionType == 2){
return new Geofence.Builder()
.setRequestId(id)
.setTransitionTypes(transitionType )
.setLoiteringDelay(10000)
.setCircularRegion(latitude, longitude, radius)
.setExpirationDuration(Long.MAX_VALUE).build();
} else {
return new Geofence.Builder()
.setRequestId(id)
.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER |Geofence.GEOFENCE_TRANSITION_EXIT )
.setLoiteringDelay(10000)
.setCircularRegion(latitude, longitude, radius)
.setExpirationDuration(Long.MAX_VALUE).build();
}

}

public String toJson() {
return Gson.get().toJson(this);
}

public static GeoNotification fromJson(String json) {
if (json == null) return null;
if (json == null ) return null;
return Gson.get().fromJson(json, GeoNotification.class);
}
}
}
Loading