diff --git a/CHANGELOG.md b/CHANGELOG.md index 26dda92..8110583 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,3 +18,8 @@ ## 0.0.4 - Fixed location object in the location receiver. + +## 0.0.5 + +- Updated Android SDK v0.1.7 +- Fixed location receiver output diff --git a/package.json b/package.json index 94be5fc..bdaa7cb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "roam-cordova", - "version": "0.0.4", + "version": "0.0.5", "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", diff --git a/src/android/.idea/.gitignore b/src/android/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/src/android/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/src/android/.idea/misc.xml b/src/android/.idea/misc.xml new file mode 100644 index 0000000..19dd268 --- /dev/null +++ b/src/android/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/android/.idea/modules.xml b/src/android/.idea/modules.xml new file mode 100644 index 0000000..e54e28e --- /dev/null +++ b/src/android/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/android/.idea/vcs.xml b/src/android/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/src/android/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/android/android.iml b/src/android/android.iml new file mode 100644 index 0000000..f76df2b --- /dev/null +++ b/src/android/android.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/android/src/main/java/com/roam/cordova/CDVRoam.java b/src/android/src/main/java/com/roam/cordova/CDVRoam.java index ca697dd..89028a9 100644 --- a/src/android/src/main/java/com/roam/cordova/CDVRoam.java +++ b/src/android/src/main/java/com/roam/cordova/CDVRoam.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.location.Location; +import android.text.TextUtils; import android.util.Log; import com.google.gson.GsonBuilder; @@ -29,6 +30,8 @@ import org.json.JSONException; import org.json.JSONObject; +import java.util.List; + public class CDVRoam extends CordovaPlugin { private static CallbackContext locationCallbackContext; private static CallbackContext eventsCallbackContext; @@ -260,7 +263,6 @@ private void getDeviceToken(CallbackContext callbackContext) { } private void setForegroundNotification(boolean enabled, String title, String description, String image, String activity){ - Log.e("TAG", "setForegroundNotification: " + enabled + title + description + image + activity); try{ String[] split = image.split("/"); String firstSubString = split[0]; @@ -271,7 +273,7 @@ private void setForegroundNotification(boolean enabled, String title, String des firstSubString, cordova.getActivity().getPackageName() ); - Roam.setForegroundNotification(enabled, title, description, resId, activity); + Roam.setForegroundNotification(enabled, title, description, resId, activity, "com.roam.cordova.RoamCDVService"); } catch (Exception e){ e.printStackTrace(); } @@ -294,7 +296,7 @@ public void onFailure(RoamError roamError) { } private void setDescription(String description) { - Roam.setDescription(description); + Roam.setDescription(description, null); } private void getUser(String userId, final CallbackContext callbackContext) { @@ -423,7 +425,7 @@ public void getCurrentLocation(int accuracy, String desired_Accuracy, final Call } Roam.getCurrentLocation(desiredAccuracy, accuracy, new RoamLocationCallback() { @Override - public void location(Location location) { + public void location(Location location, float direction) { String serializedLocation = new GsonBuilder().create().toJson(location); callbackContext.success(serializedLocation); } @@ -468,28 +470,16 @@ private void startTracking(String trackingMode){ switch (trackingMode) { case "ACTIVE": Roam.startTracking(RoamTrackingMode.ACTIVE); - startReceiverService(); break; case "BALANCED": Roam.startTracking(RoamTrackingMode.BALANCED); - startReceiverService(); break; case "PASSIVE": Roam.startTracking(RoamTrackingMode.PASSIVE); - startReceiverService(); break; } } - private void startReceiverService(){ - Activity activity = cordova.getActivity(); - activity.startService(new Intent(activity, RoamCDVService.class)); - } - - private void stopReceiverService(){ - Activity activity = cordova.getActivity(); - activity.stopService(new Intent(activity, RoamCDVService.class)); - } private void startTrackingTimeInterval(int timeInterval, String desiredAccuracy) { RoamTrackingMode.Builder builder = new RoamTrackingMode.Builder(timeInterval); @@ -505,7 +495,6 @@ private void startTrackingTimeInterval(int timeInterval, String desiredAccuracy) break; } Roam.startTracking(builder.build()); - startReceiverService(); } private void startTrackingDistanceInterval(int distance, int stationary, String desiredAccuracy) { @@ -522,12 +511,10 @@ private void startTrackingDistanceInterval(int distance, int stationary, String break; } Roam.startTracking(builder.build()); - startReceiverService(); } private void stopTracking() { Roam.stopTracking(); - stopReceiverService(); } @@ -598,29 +585,14 @@ public static void safeRemoveCallback(){ public static class RoamCordovaReceiver extends RoamReceiver{ @Override - public void onLocationUpdated(Context context, RoamLocation roamLocation) { + public void onLocationUpdated(Context context, List roamLocation) { super.onLocationUpdated(context, roamLocation); - JSONObject jsonObject = new JSONObject(); + String serializedLocation = ""; try { - jsonObject.put("userId", roamLocation.getUserId()); - jsonObject.put("activity", roamLocation.getActivity()); - jsonObject.put("recordedAt", roamLocation.getRecordedAt()); - jsonObject.put("timezoneOffset", roamLocation.getTimezoneOffset()); - jsonObject.put("metadata", (roamLocation.getMetadata() != null) ? roamLocation.getMetadata().toString() : ""); - jsonObject.put("batteryStatus", roamLocation.getBatteryStatus()); - jsonObject.put("networkStatus", roamLocation.getNetworkStatus()); - jsonObject.put("provider", roamLocation.getLocation().getProvider()); - jsonObject.put("time", roamLocation.getLocation().getTime()); - jsonObject.put("latitude", roamLocation.getLocation().getLatitude()); - jsonObject.put("longitude", roamLocation.getLocation().getLongitude()); - jsonObject.put("altitude", roamLocation.getLocation().getAltitude()); - jsonObject.put("speed", roamLocation.getLocation().getSpeed()); - jsonObject.put("bearing", roamLocation.getLocation().getBearing()); - jsonObject.put("accuracy", roamLocation.getLocation().getAccuracy()); - }catch (Exception e){ + serializedLocation = mapForLocationList(roamLocation).toString(); + } catch (JSONException e) { e.printStackTrace(); } - String serializedLocation = jsonObject.toString(); PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, serializedLocation); pluginResult.setKeepCallback(true); if (CDVRoam.locationCallbackContext != null) { @@ -652,5 +624,40 @@ public void onError(Context context, RoamError roamError) { String serializedLocation = new GsonBuilder().create().toJson(roamError); errorCallbackContext.success(serializedLocation); } + + private JSONArray mapForLocationList(List locationList) throws JSONException { + JSONArray array = new JSONArray(); + for (RoamLocation roamLocation: locationList){ + JSONObject map = new JSONObject(); + map.put("userId", (roamLocation.getUserId() != null) ? roamLocation.getUserId() : ""); + map.put("location", mapForLocation(roamLocation.getLocation())); + if (TextUtils.isEmpty(roamLocation.getActivity())) { + map.put("activity", " "); + } else { + map.put("activity", roamLocation.getActivity()); + } + map.put("recordedAt", roamLocation.getRecordedAt()); + map.put("timezone", roamLocation.getTimezoneOffset()); + array.put(map); + } + return array; + } + + private JSONObject mapForLocation(Location location){ + JSONObject map = new JSONObject(); + if (location == null) { + return map; + } + try { + map.put("latitude", location.getLatitude()); + map.put("longitude", location.getLongitude()); + map.put("accuracy", location.getAccuracy()); + map.put("altitude", location.getAltitude()); + map.put("speed", location.getSpeed()); + } catch (JSONException e) { + } + return map; + } + } } \ No newline at end of file diff --git a/src/android/src/main/java/com/roam/cordova/roam-sdk.gradle b/src/android/src/main/java/com/roam/cordova/roam-sdk.gradle index 1cfbac9..034bac0 100644 --- a/src/android/src/main/java/com/roam/cordova/roam-sdk.gradle +++ b/src/android/src/main/java/com/roam/cordova/roam-sdk.gradle @@ -5,5 +5,5 @@ repositories { } } dependencies { - implementation 'com.roam.sdk:roam-android:0.1.1' + implementation 'com.roam.sdk:roam-android:0.1.7' } \ No newline at end of file