Before starting these procedures, make sure you have enabled the appropriate
services and the Consumer SDK as described in earlier sections.

To initialize the Consumer SDK, follow these steps:

1. [Get the `ConsumerAPI` instance](https://developers.google.com/maps/documentation/mobility/journey-sharing/on-demand/android/init-sdk.md.txt#getinstance)
2. [Initialize Maps SDK to request for preferred renderer](https://developers.google.com/maps/documentation/mobility/journey-sharing/on-demand/android/init-sdk.md.txt#init-maps)

## Get the `ConsumerApi` instance

To use the Consumer SDK, your app needs to initialize the singleton
`ConsumerApi` asynchronously. The initialization method takes the
`AuthTokenFactory` class to generate new JWT tokens for the user when necessary.

The `providerId` is the **Project ID** of your Google Cloud Project. For more
information about creating a Fleet Engine project, see
[Create your Fleet Engine project](https://developers.google.com/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/create-project.md.txt) in the Fleet Engine guide.

Your app should implement the `AuthTokenFactory` as described in [Consumer SDK
Authentication](https://developers.google.com/maps/documentation/mobility/journey-sharing/on-demand/android/auth-sdk).

### Java

```java
Task<ConsumerApi> consumerApiTask = ConsumerApi.initialize(
    this, "myProviderId", authTokenFactory);

consumerApiTask.addOnSuccessListener(
  consumerApi -> this.consumerApi = consumerApi);
```

### Kotlin

```kotlin
val consumerApiTask =
  ConsumerApi.initialize(this, "myProviderId", authTokenFactory)

consumerApiTask?.addOnSuccessListener { consumerApi: ConsumerApi ->
  this@YourActivity.consumerApi = consumerApi
}
```

## Maps SDK and maps renderers

The Consumer SDK v2.0.0 and later support the Maps SDK for Android v18.1.0 and
later. The following table summarizes the default renderer by Maps SDK version
and the supportability of both renderers. If possible, use the latest renderer.
If you must use the legacy renderer, explicitly specify it using
[`MapsInitializer.initialize()`](https://developers.google.com/android/reference/com/google/android/gms/maps/MapsInitializer.md.txt).

| Maps SDK version | Supports the latest renderer | Supports the legacy renderer | Default renderer |
|---|---|---|---|
| V18.1.0 and below | Yes | Yes | Legacy\* |
| V18.2.0 | Yes | Yes | Latest |

\* With the rollout of [new Maps Renderer](https://developers.google.com/maps/documentation/android-sdk/renderer.md.txt#rollout_schedule), the Latest renderer will be the
default.

If you must use a preferred renderer, run all UI-rendering operations
**after** `OnMapsSdkInitializedCallback` returns a result. UI-rendering
operations include the following operations:

- Inflating a view that contains `GoogleMapView` or `ConsumerMapView`.

- Placing markers on `ConsumerMapView`.

If you don't run these operations after receiving the
`OnMapsSdkInitializedCallback` result, the Maps SDK doesn't allocate your
preferred renderer and the map view is instead rendered by the default renderer.

## Initialize Maps SDK before initializing the Consumer SDK

1. In your `Application` or start-up `Activity` class, call
   [MapsInitializer.initialize()](https://developers.google.com/maps/documentation/android-sdk/renderer.md.txt)

2. Wait for the renderer request result before initializing the Consumer SDK.

See the following examples for details.

### Java

```java
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  initViews();

  MapsInitializer.initialize(getApplicationContext(), Renderer.LATEST,
      new OnMapsSdkInitializedCallback() {
        @Override
        public void onMapsSdkInitialized(Renderer renderer) {
          switch (renderer) {
            case LATEST:
              Log.i("maps_renderer", "LATEST renderer");
              break;
            case LEGACY:
              Log.i("maps_renderer", "LEGACY renderer");
              break;
          }

          initializeConsumerSdk();
        }
      });
}
```

### Kotlin

```kotlin
fun onCreate(savedInstanceState: Bundle?) {
  super.onCreate(savedInstanceState)
  setContentView(R.layout.main)
  initViews()

  MapsInitializer.initialize(
    getApplicationContext(), Renderer.LATEST,
    object : OnMapsSdkInitializedCallback() {
      fun onMapsSdkInitialized(renderer: Renderer?) {
        when (renderer) {
          LATEST -> Log.i("maps_renderer", "LATEST renderer")
          LEGACY -> Log.i("maps_renderer", "LEGACY renderer")
        }
        initializeConsumerSdk()
      }
    })
  }
```

## Notes on SSL/TLS

Internally, the Consumer SDK implementation uses SSL/TLS to communicate securely
with the Fleet Engine service. Android API versions 23 or earlier may require a
`SecurityProvider` patch to communicate with the server. For more information
about working with SSL in Android, see [Security GMS
Provider](https://developer.android.com/training/articles/security-gms-provider).
The article also contains code samples for patching the security provider.

## What's next

[Set up a map](https://developers.google.com/maps/documentation/mobility/journey-sharing/on-demand/android/create-ui.md.txt)