Test & Troubleshoot

Enable Debug Mode

Debug mode allows you to view debug logs for the Movement SDK so you can quickly spot any configuration errors and better understand SDK states.

In Android, the class DebugActivity contains the view for debug mode and is available to developers using the SDK. Developers who wish to display debug mode can do so with the following implementation instructions:

1. Configure the Movement SDK

See the Get Started to ensure the SDK is configured correctly.

2. Add debug dependency

In your build.gradle file's dependencies, include:

com.foursquare:movementsdk-debugging:4.0.0

3. Turn logging on

When using the builder to instantiate the SDK, make sure you enable debug logs and set the log level to Debug:

MovementSdk.Builder builder = new MovementSdk.Builder(this)
    .consumer(BuildConfig.YOUR_FSQ_CLIENT_KEY, BuildConfig.YOUR_FSQ_CLIENT_SECRET)
    .logLevel(LogLevel.DEBUG)
    .enableDebugLogs();
MovementSdk.with(builder);
val builder = PilgrimSdk.Builder(this)
    .consumer(BuildConfig.PILGRIM_API_CLIENT_KEY, BuildConfig.PILGRIM_API_CLIENT_SECRET)
    .logLevel(LogLevel.DEBUG)
    .enableDebugLogs()
PilgrimSdk.with(builder)

4. Using Live Debug Logging

Since 2.4, when configuring the MovementSdk instance, there is a new method added to improve the integration and developer debugging experience. For developer builds, you can now call enableLiveConsoleEvents on the MovementSdk.Builder instance. This will enable all events coming from the device to show up in the Movement SDK console on the Foursquare Developer console and give you an opportunity to monitor behavior of your Pilgrim integration without having to preconfigure devices in the console ahead of time.

Note: You should only enable this for internal builds of your application. Make sure it is turned off in your production build.

MovementSdk.Builder builder = new MovementSdk.Builder(this)
    .consumer(BuildConfig.YOUR_FSQ_CLIENT_KEY, BuildConfig.YOUR_FSQ_CLIENT_SECRET)
    .logLevel(LogLevel.DEBUG)
    .enableLiveConsoleEvents();
PilgrimSdk.with(builder);
val builder = PilgrimSdk.Builder(this)
    .consumer(BuildConfig.PILGRIM_API_CLIENT_KEY, BuildConfig.PILGRIM_API_CLIENT_SECRET)
    .logLevel(LogLevel.DEBUG)
    .enableLiveConsoleEvents()
PilgrimSdk.with(builder)

5. Decide View Options

You can show debug mode through a gesture or button. Decide on how you want to show debug mode and ensure you have the application’s context available to start the activity.

6. Start Activity with New Intent

startActivity(new Intent(this, DebugActivity.class))
val debugIntent = Intent(this, PilgrimSdkDebugActivity::class.java)
startActivity(debugIntent)

To avoid errors, the variable this should be of type Context

Missing Test Visits

By default, Android's debug mode events do not auto update, requiring you to close and reopen the debug mode view to see new activity (including when triggering test visits from the debug mode). You can enable auto autodating by turning on the "Tail" feature available from the debug mode's menu.

Test a Visit

With the Movement SDK properly configured, the notification handlers hit whenever you arrive or depart one of our 105M+ places around the world. In order to test your visit callback without physically walking around, we provide a test method:

  • NotificationTester.sendTestVisitArrivalAtLocation can test your NotificationHandler implementation without moving around. By passing a latitude and longitude, this method communicates with the Foursquare servers and sends back a notification if the location matches your configuration.
void NotificationTester.sendTestVisitArrivalAtLocation(
        @NonNull Context context,
        double lat,
        double lng,
        boolean isDeparture
)

Reasons for a getCurrentLocation nil or error response

There are a couple reasons that calling getCurrentLocation would return an error or a nil value:

  1. Lack of network connectivity: The most likely reason the SDK cannot retrieve the device's current location would be because the API request has failed to make a proper connection to the Foursquare server.
  2. Lack of location permissions: If the proper location permissions have not been properly set or granted by the user.
  3. getCurrentLocation is being run from the main thread.

Targeting Android Marshmallow

If you are using targetSdk 23, then you will need to make sure that your app requests the ACCESS_FINE_LOCATION permission. Pilgrim will not run without the location permission. Once your user accepts the location permission, you should call PilgrimSdk.start(context).

public void requestLocationPermission(Activity activity, int requestCode) {
    ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
            requestCode);
}