Documentation Index
Fetch the complete documentation index at: https://smartcar.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
Overview

- The Mobile Application launches a
Chrome Custom Tabwith Smartcar Connect to request access to a user’s vehicle. On Connect, the user logs in with their vehicle credentials and grants the Application access to their vehicle. - The
Chrome Tabis redirected to a specifiedREDIRECT_URIalong with auser_idandstate. This will be the custom scheme set on the application. The Smartcar Android SDK receives the response in a view listening for the specified custom scheme URI, and passes it to the Mobile Application. - The Mobile Application sends the received
user_idto the Application’s backend service for storage. - The Application’s backend authenticates with the Smartcar API using the OAuth 2.0 Client Credentials flow to obtain an application-level access token.
- Using the access token and the
sc-user-idheader, the Application can now send requests to the Smartcar API. It can access protected resources and send commands to and from the user’s vehicle via the backend service.
Prerequisites
- Sign up for a Smartcar account.
- Make a note of your
CLIENT_IDandCLIENT_SECRETfrom the Configuration section on the Dashboard. - Add a custom scheme redirect URI to your application configuration.
- Add the
app_serverredirect URI from Setup step 2. to your application configuration.
For Android, we require the custom URI scheme to be in the format of
sc + clientId + :// + hostname.
For now, you can just set it to sc + clientId + ://exchange.Please see our Connect Docs for more information.Setup
-
Clone our repo and install the required dependencies:
Do not “checkout from version control” with the Getting Started repo in Android Studio, as it will not open the proper module.
-
Open
getting-started-android-sdk/tutorialin Android Studio as an existing project and build from existing sources. Android Studio should automatically import the required dependencies and build gradle. We’re settingapp_servertohttp://10.0.2.2:8000to pass the authorizationcodefrom the Handle the Response step later on in the tutorial to our backend.strings.xml
Build your Connect URL
- Instantiate a
smartcarAuthobject in theonCreatefunction of theMainActivity.MainActivity.java
The Android SDK does not support
simulated mode at this time - only test and live.
Feel free to set testMode to false where you instantiate your SmartcarAuth object to
connect to a real vehicle.-
The Android application will launch a Chrome Tab with Smartcar Connect to request access to a user’s vehicle.
On Connect, the user logs in with the username and password for their vehicle’s connected services account and grants the application access to their vehicle.
To launch Connect, we can use the
addClickHandlerfunction that oursmartcarAuthobject has access to.MainActivity.java
Registering your Custom Scheme
Once a user has authorized the application to access their vehicle, the user is redirected to theREDIRECT_URI with an authorization code as a query parameter.
Android applications use custom URI schemes to intercept calls and launch the relevant application. This is defined within the AndroidManifest.
AndroidManifest.xml
Handle the response
Using the Android SDK, the application can receive the code in theSmartcarCallback object passed into the SmartcarAuth object.
MainActivity.java
Launching Connect
Build your application in Android Studio and click on the Connect your vehicle button.This tutorial configures Connect to launch in
test mode by default.
In test mode, any username and password is valid for each brand.read_vehicle_info in this case.
Once you have logged in and accepted the permissions, you should see your authorization code printed to your console.
Sending the user_id to your backend
After the user completes the Connect flow, your Android application receives auser_id. Send this to your backend service for storage — your backend will use it as the sc-user-id header when making API requests on behalf of this user.
MainActivity.java
Getting data from a vehicle
Once your backend has theuser_id and an application-level access token, it can send requests to a vehicle using the Smartcar API. The Android app will
have to send a request to the backend service which in turn sends a request to Smartcar. We have to do this because
our frontend does not have the access token.
Assuming our backend has a /vehicle endpoint that returns the information of a user’s vehicle, we can make this query in
our completion callback and start another activity to show the returned vehicle attributes.
MainActivity.java
Setting up your backend
Now that our frontend is complete, we will need to create a backend service that stores theuser_id and handles API authentication. Your backend will use the OAuth 2.0 Client Credentials flow to obtain an application-level access token and make requests to vehicles.
You can use any of our backend SDKs below to set up the service.
When setting up the environment variables for your backend SDK, make sure to set
REDIRECT_URI to the custom scheme
used for this tutorial i.e. sc + "clientId" + ://exchange.
