Supplementary for Android

The following information enables you to create a mock trip for the mobile app.

Simulate trips

When you start a mock trip, a route will be generated from the startLocation to the test site. Location updates will be sent to the ARRIVE server at regular intervals. To cancel a mock trip, use cancelMockTrip.

Start a Mock Trip

Use the following code snippet to start a mock trip to your site. Replace the startLocation's latitude and longitude with a location that is two or three miles from your site.

final LatLng startLocation = new LatLng(37.427507, -122.138655);
CSUserSession.getInstance().startMockTripToSiteWithIdentifier("SITE_ID", startLocation);

You can also subscribe to EventBus before calling this method to listen for successful or failed events for the method using the following code snippet:

    //create an observer for listening start mock trip event 
    final Action1<Event> startMockTripToSiteEventObserver = new Action1<Event>() {
        @Override
        public void call(Event event) {
            if(event.status == Status.SUCCESS) {
                Log.d(TAG, String.format("Succesfully started mock trip to site"));
                //do something 
            }
            else if (event.status == Status.FAILURE) {
                Log.d(TAG, String.format("Unsuccessful in starting mock trip to site due to: %s", (CSErroCode)event.object));
                //do something 
            }
        }
    };
 
//subscribe to the event on the eventBus 
CSUserSession.getInstance().getEventBus().getObservable(Path.USER, START_MOCK_TRIP).subscribe(startMockTripToSiteEventObserver);

Cancel a Mock Trip

Use the following code snippet to cancel a mock trip:

CSUserSession.getInstance().cancelMockTrip();

You can also subscribe to EventBus before calling this method to listen for successful or failed events for the method using the following code snippet:

    //create an observer for listening cancel mock trip event 
    final Action1<Event> cancelMockTripToSiteEventObserver = new Action1<Event>() {
        @Override
        public void call(Event event) {
            if(event.status == Status.SUCCESS) {
                Log.d(TAG, String.format("Succesfully cancelled mock trip to site"));
                //do something 
            }
            else if (event.status == Status.FAILURE) {
                Log.d(TAG, String.format("Unsuccessful in cancelling mock trip to site due to: %s", (CSErroCode)event.object));
                //do something 
            }
        }
    };
 
//subscribe to the event on the eventBus 
CSUserSession.getInstance().getEventBus().getObservable(Path.USER, CANCEL_MOCK_TRIP).subscribe(cancelMockTripToSiteEventObserver);

Integrate FCM in Apps without FCM integrated in them.

Follow the steps to integrate FCM functionality in your app. (source: Firebase)

Step 1: Add Firebase in your app

  1. Go to Firebase Console and click Add project.

Image of Firebase Console

  1. Following pop up window will open. Click on the drop down marker in front of Project Name. Select the project from the list of existing Google Projects and then click “Add Firebase”.

Image of Add Project

  1. Click Add Firebase to your Android app and follow the setup steps.
  2. When prompted, enter your app's package name. Package name can only be set when you add an app to your Firebase project.
  3. At the end, you'll download a google-services.json file. You can download this file again at any time.
  4. Copy google-services.json file into your project's module folder, typically app.

Step 2: Add the Firebase SDK in your app:

  1. First, add rules to your root-level build.gradle file, to include the google-services plugin and the Google's Maven repository:
buildscript {
    // ... 
    dependencies {
        // ... 
        classpath 'com.google.gms:google-services:3.0.0' // google-services plugin 
    }
}
 
allprojects {
    // ... 
    repositories {
        // ... 
        maven {
            url "https://maven.google.com" // Google's Maven repository 
        }
    }
}
  1. Then, in your module Gradle file (usually the app/build.gradle), add the apply plugin line at the bottom of the file to enable the Gradle plugin:
apply plugin: 'com.android.application'
android {
    // ... 
}
dependencies {
    // ... 
    compile 'com.google.firebase:firebase-core:11.6.2'
    compile 'com.google.firebase:firebase-messaging:11.6.2'
}
 
// ADD THIS AT THE BOTTOM 
apply plugin: 'com.google.gms.google-services'
  1. Make sure that all the google dependencies are of the same version. Otherwise, app may throw errors/exceptions when running/syncing the project.

Step 3: Test the FCM setup:

Curbside SDK provides FCM Listener and FCM token generator. Whenever you will initialize the Curbside SDK, the FCM token will be generated. This token will be logged in the logcat. Make sure to copy it as it will be used in upcoming steps. Using this token, the Firebase Console will identify your device and push the notification to it. Sample Push token line in logcat will look like:

D/CSUserSession: FCM Push token is cE7TsygX66Y:APA91bF1e2BAvVW-VNB1BdSr01hO40AX8raakUbAzzWq9eW_7t48XrrHXY9x58zBtPIevKtTQWUabyzIHsKNx9EoZWXJ5XCZ4b85RGPmV9F-AFba6fGne3uO6RlZZAidDYXzR8Rod_Xm
                                            Or
D/FirebaseInstanceIdSvc: Refreshed Token is: cE7TsygX66Y:APA91bF1e2BAvVW-VNB1BdSr01hO40AX8raakUbAzzWq9eW_7t48XrrHXY9x58zBtPIevKtTQWUabyzIHsKNx9EoZWXJ5XCZ4b85RGPmV9F-AFba6fGne3uO6RlZZAidDYXzR8Rod_Xm
  1. Login to Google Firebase Console.
  2. Select your project.
  3. Scroll down to Grow and click on Notifications:

Image of Grow

  1. Following screen will open. Click on “Send your first message”.

Image of Send First FCM

  1. Fill in the Message Text. Select the “Single Device” option for target. Insert the previously copied FCM registration token. Click on Advanced Options.

Image of Compose FCM

  1. Put “cscmd” as the key and “99” as the value. Click “Send Message”

Image of Compose FCM

  1. If everything is setup correctly, you will see Message Status is “Completed” in Firebase Console. And in the logcat of Android Studio, there will be a log saying FCM Test Successful.

Image of FCM Successfully sent

Step 4:: Retrieve the Server Key for the FCM Api in Firebase Console.

  1. Login to Google Firebase Console.
  2. Select your project and click the settings "gear" icon in the upper-left and select Project settings.

Image of Project Settings

  1. Click on the "Cloud Messaging" tab

Image of Goto Cloud Messaging

  1. On this page you will find your Server key, Legacy Server key and Sender ID.

Image of Server Keys

  1. Curbside will need the Legacy Server Key to push notifications to the app. App package name is also required.

  2. Make sure that this Api key is enabled in the Google Developer Console dashboard for your project.

Integrate FCM in Apps with FCM integrated in them.

  1. Provide Curbside the “Legacy Server Key” for FCM Api from your Firebase Console. Curbside will use it to push notifications to the app. Follow these steps, in case, you need to know how to retrieve the key. App package name is also required.

  2. Whenever FCM is received in your app’s FirebaseMessagingService, pass the payload to the Curbside SDK. Use following Api to pass the payload. The Api will return true if it contains payload that SDK can process, otherwise it will return false.

final boolean canHandleRemoteNotification = CSUserSession.getInstance().handlePushNotification(remoteMessage /*Remote Message*/)
if(canHandleRemoteNotification)
    Log.d(TAG, "Curbside SDK can handle FCM");
else
    Log.d(TAG, "Curbside SDK cannot handle FCM");
  1. To test the FCM, follow these steps. If everything is setup correctly, you will see Message Status is “Completed” in Firebase Console. Also, in the logcat of Android Studio, there will be a log saying "CurbsideSDK can handle FCM".