Headless
Utilize our Headless SDK for ultimate flexibility. This guide provides detailed instructions on integrating custom UI elements with OTPLESS’s backend authentication functions.
Step 1: Add SDK Dependency
To get started, incorporate the OTPLESS SDK into your project. Update your app’s build.gradle
file by adding the following dependency:
implementation 'io.github.otpless-tech:otpless-android-sdk:2.3.3'
Make sure to synchronize
your Gradle project to fetch the dependency.
Step 2: Configure AndroidManifest.xml
Modify your AndroidManifest.xml
to include an intent filter within the activity responsible for sign-up or sign-in. This setup is crucial for handling deep links.
<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:host="otpless" android:scheme="otpless.{{YOUR_APP_ID}}" />
</intent-filter>
Replace YOUR_APP_ID
with your actual App
ID provided in
your OTPLESS dashboard.
Additionally, ensure your activity is set to singleTop
launch mode and exported
attribute is true:
android:launchMode="singleTop"
android:exported="true"
Step 3: Configure Your Signup/Sign In Activity
Import SDK Classes
First, import necessary classes from the OTPLESS SDK:
import com.otpless.main.OtplessManager;
import com.otpless.main.OtplessView;
import com.otpless.dto.HeadlessRequest;
import com.otpless.dto.HeadlessResponse;
import com.otpless.dto.HeadlessChannelType;
Declare an OtplessView
instance:
OtplessView otplessView;
Within your onCreate()
method, initialize and set up the OTPLESS Sign in:
// Initialise OtplessView
otplessView = OtplessManager.getInstance().getOtplessView(this);
otplessView.initHeadless("YOUR_APP_ID", savedInstanceState);
otplessView.setHeadlessCallback(this::onHeadlessCallback);
otplessView.verifyIntent(getIntent());
Replace YOUR_APP_ID
with your actual App
ID provided in
your OTPLESS dashboard.
Step 4: Handle Callback
Implement a callback method to handle the response from the OTPLESS SDK:
private void onHeadlessCallback(@NonNull final HeadlessResponse response) {
if (response.getStatusCode() == 200) {
JSONObject successResponse = response.getResponse();
} else {
String error = response.getResponse().optString("errorMessage");
}
}
Override onNewIntent()
Ensure you override the onNewIntent()
method to correctly handle intent verification:
if (otplessView != null) {
otplessView.verifyIntent(intent);
}
Step 5: Handle Back Press
Override the onBackPressed()
method to manage back press actions properly:
// make sure you call this code before super.onBackPressed();
if (otplessView.onBackPressed()) return;
Step 6: Initiate Authentication
Initiate the authentication process based on the user’s selected method by using the initiate
method of the SDK.
(Optional): Verify OTP
To verify the OTP entered by the user, use the verify
method with the necessary parameters.
Object Attributes
Attribute | Mandatory | Description |
---|---|---|
channel | Yes | The authentication method selected by the user. |
phone | Conditional | User’s phone number (required if channel is PHONE). |
countryCode | Conditional | Country code of the phone number (required if channel is PHONE). |
email | Conditional | User’s email (required if channel is EMAIL). |
channelType | Conditional | Type of social login initiated (required if channel is OAUTH). |
Was this page helpful?