In this tutorial, we will use the Android SDK to integrate Connect into your application.
Chrome Custom Tab
with 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.Chrome Tab
is redirected to a specified REDIRECT_URI
along with an authorization code
.
This will be the custom scheme set on the application. The Smartcar Android receives the authorization code
in a view listening
for the specified custom scheme URI, and passes it to the Mobile Application.code
to the Application’s backend service.CLIENT_ID
and CLIENT_SECRET
.ACCESS_TOKEN
and a REFRESH_TOKEN
.ACCESS_TOKEN
, 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.CLIENT_ID
and CLIENT_SECRET
from the Configuration section on the Dashboard.app_server
redirect URI from Setup step 2. to your application configuration.sc
+ clientId
+ ://
+ hostname
.
For now, you can just set it to sc
+ clientId
+ ://exchange
.Please see our Connect Docs for more information.getting-started-android-sdk/tutorial
in Android Studio as an existing project and build from existing sources.
Android Studio should automatically import the required dependencies and build gradle. We’re setting app_server
to http://10.0.2.2:8000
to pass the authorization code
from the Handle the Response step later on in the tutorial to our backend.
smartcarAuth
object in the onCreate
function of the MainActivity
.
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.addClickHandler
function that our smartcarAuth
object has access to.
REDIRECT_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
.
SmartcarCallback
object passed into the SmartcarAuth
object.
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.
code
, your iOS application must exchange it for an ACCESS_TOKEN
. To do so, we can send
the code to a backend service. Let’s assume our backend service contains an endpoint /exchange
that receives an authorization code
as a query parameter and exchanges it for an ACCESS_TOKEN
.
ACCESS_TOKEN
.
This is by design. For security, our frontend should never have access
to the ACCESS_TOKEN
and should always be stored in the backend.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.
/exchange
and /vehicle
endpoints.
You can use any of our backend SDKs below to set up the service starting from the Obtaining an Access Token step.
REDIRECT_URI
to the custom scheme
used for this tutorial i.e. sc + "clientId" + ://exchange
.