smartcar-auth

Smartcar Android Auth SDK

License

License

GroupId

GroupId

com.smartcar.sdk
ArtifactId

ArtifactId

smartcar-auth
Last Version

Last Version

3.1.0
Release Date

Release Date

Type

Type

aar
Description

Description

smartcar-auth
Smartcar Android Auth SDK
Project URL

Project URL

https://github.com/smartcar/android-sdk
Source Code Management

Source Code Management

https://github.com/smartcar/android-sdk.git

Download smartcar-auth

How to add to project

<!-- https://jarcasting.com/artifacts/com.smartcar.sdk/smartcar-auth/ -->
<dependency>
    <groupId>com.smartcar.sdk</groupId>
    <artifactId>smartcar-auth</artifactId>
    <version>3.1.0</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.smartcar.sdk/smartcar-auth/
implementation 'com.smartcar.sdk:smartcar-auth:3.1.0'
// https://jarcasting.com/artifacts/com.smartcar.sdk/smartcar-auth/
implementation ("com.smartcar.sdk:smartcar-auth:3.1.0")
'com.smartcar.sdk:smartcar-auth:aar:3.1.0'
<dependency org="com.smartcar.sdk" name="smartcar-auth" rev="3.1.0">
  <artifact name="smartcar-auth" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.smartcar.sdk', module='smartcar-auth', version='3.1.0')
)
libraryDependencies += "com.smartcar.sdk" % "smartcar-auth" % "3.1.0"
[com.smartcar.sdk/smartcar-auth "3.1.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

Smartcar Android Auth SDK Build Status Coverage Download

The SmartcarAuth Android SDK makes it easy to integrate with Smartcar Connect from Android.

Reference Documentation

Installation

Add the following to your application's build.gradle dependencies:

dependencies {
    implementation 'com.smartcar.sdk:smartcar-auth:3.0.0'
    implementation 'androidx.browser:browser:1.0.0'
}

Redirect URI Setup

Your application must register a custom URI scheme in order to receive Connect's response. Smartcar requires the custom URI scheme to be in the format of "sc" + clientId + "://" + hostname. This URI must also be registered in Smartcar's developer portal for your application. You may append an optional path component or TLD. For example, a redirect uri could be:

sc4a1b01e5-0497-417c-a30e-6df6ba33ba46://myapp.com/callback

You will then need to register the URI in the AndroidManifest.xml by inserting a new activity with an intent filter. More information on the data element.

<activity android:name="com.smartcar.sdk.SmartcarCodeReceiver">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data
            android:scheme="sc4a1b01e5-0497-417c-a30e-6df6ba33ba46"
            android:host="myapp.com"
            android:path="/callback" />
    </intent-filter>
</activity>

Usage

  1. Instantiate a new SmartcarAuth instance with a SmartcarCallback handler:
import com.smartcar.sdk.SmartcarAuth;
import com.smartcar.sdk.SmartcarCallback;
import com.smartcar.sdk.SmartcarResponse;

SmartcarAuth smartcarAuth = new SmartcarAuth(
    "your-client-id",
    "your-redirect-uri",
    new String[] {"read_vehicle_info", "read_odometer"},

    // Create a callback to handle the redirect response
    new SmartcarCallback() {
        @Override
        public void handleResponse(SmartcarResponse smartcarResponse) {
            // Retrieve the authorization code
            Log.d("SmartcarAuth", "Authorization code: " + smartcarResponse.getCode());
        }
});
  1. Launch the Smartcar Connect flow:
smartcarAuth.launchAuthFlow(getApplicationContext());

Alternatively, add a click handler to any view to launch the Smartcar Connect flow.

Button connectButton = findViewById(R.id.connect_button);
smartcarAuth.addClickHandler(getApplicationContext(), connectButton);
  1. Use the AuthUrlBuilder for additional configuration:
String authUrl = smartcarAuth.authUrlBuilder()
    .setState("foo")
    .setForcePrompt(true)
    .setMakeBypass("TESLA")
    .build();

// Launch Smartcar Connect with the configured parameters
smartcarAuth.launchAuthFlow(getApplicationContext(), authUrl);

// Alternatively attach a click handler
Button connectButton = findViewById(R.id.connect_button);
smartcarAuth.addClickHandler(getApplicationContext(), button, authUrl);

Contributing

Please use Android Studio 3.5 to develop on the Smartcar Android SDK.

com.smartcar.sdk

Smartcar

Versions

Version
3.1.0
3.0.0
2.1.1
2.1.0
2.0.0
1.2.1
1.2.0
1.1.1
1.1.0
1.0.4
1.0.3