Skip to content

Commit

Permalink
Merge pull request #2 from roam-ai/RC-830
Browse files Browse the repository at this point in the history
v0.0.3
  • Loading branch information
Jothi Priyadharshan authored Aug 8, 2022
2 parents 7aa8cc6 + 847f073 commit 4147ad7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@
- Fixed time and distance based tracking methods
- Fixed location listener
- Fixed `requestLocationPermission` and `requestBackgroundLocationPermission` methods

## 0.0.3

- Fixed location listener
- Added `safeRemoveCallback` method to prevent app side crash for terminated state
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,14 @@ cordova.plugins.roam.offEvents();
cordova.plugins.roam.offError();
```

## Headless JS

Headless JS allows JS code to run in isolate when app is terminated. Cordova doesn't have a mechanism for headless JS. To use location updates for terminated state, business logic can be added in `onLocationUpdated` method in `RoamCordovaReceiver` class in `CDVROAM.java`

***NOTE***

`safeRemoveCallback` should be called in `onDestory` method of MainActivity to prevent terminated state crash.

## Set Foreground Notification

To set foreground notification, use the below method.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "roam-cordova",
"version": "0.0.2",
"version": "0.0.3",
"description": "This plugin allows to use the Roam.ai SDK in your React Native mobile application on iOS and Android.",
"homepage": "https://roam.ai",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<plugin
id="roam-cordova"
version="0.0.2"
version="0.0.3"
xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android">
<name>roam</name>
Expand Down
20 changes: 16 additions & 4 deletions src/android/src/main/java/com/roam/cordova/CDVRoam.java
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ public void onFailure(RoamError roamError) {
}

private void onLocation(final CallbackContext callbackContext) {
locationCallbackContext = callbackContext;
CDVRoam.locationCallbackContext = callbackContext;
}

private void onEvents(final CallbackContext callbackContext) {
Expand All @@ -567,7 +567,7 @@ private void onError(final CallbackContext callbackContext) {
}

private void offLocation() {
locationCallbackContext = null;
CDVRoam.locationCallbackContext = null;
}

private void offEvents() {
Expand All @@ -591,19 +591,31 @@ private static String permissionsStatus(boolean hasPermissionsGranted) {
return "DENIED";
}

public static void safeRemoveCallback(){
CDVRoam.locationCallbackContext = null;
}

public static class RoamCordovaReceiver extends RoamReceiver{
@Override
public void onLocationUpdated(Context context, RoamLocation roamLocation) {
super.onLocationUpdated(context, roamLocation);
String serializedLocation = new GsonBuilder().create().toJson(roamLocation);
locationCallbackContext.success(serializedLocation);
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, serializedLocation);
pluginResult.setKeepCallback(true);
if (CDVRoam.locationCallbackContext != null) {
CDVRoam.locationCallbackContext.sendPluginResult(pluginResult);
} else {
//Business logic can be added here for terminated state
//safeRemoveCallback should be called in the MainActivity
}

}

@Override
public void onLocationReceived(Context context, RoamLocationReceived roamLocationReceived) {
super.onLocationReceived(context, roamLocationReceived);
String serializedLocation = new GsonBuilder().create().toJson(roamLocationReceived);
locationCallbackContext.success(serializedLocation);
CDVRoam.locationCallbackContext.success(serializedLocation);
}

@Override
Expand Down

0 comments on commit 4147ad7

Please sign in to comment.