---
"@context": https://schema.org
"@type": TechArticle
"@id": https://www.twilio.com/docs/verify/tutorials/android-sdk-integration-sample-backend#article
headline: Integrating Twilio Verification SDK for Android using the sample backend
description: Learn how to integrate the Twilio Verification SDK for Android using a sample backend in this guide.
url: https://www.twilio.com/docs/verify/tutorials/android-sdk-integration-sample-backend
inLanguage: en
dateModified: 2026-06-25T22:34:50.000Z
author:
  "@type": Organization
  name: Twilio Developer Education Team
publisher:
  "@type": Organization
  name: Twilio
---

# Integrating Twilio Verification SDK for Android using the sample backend

This guide is part of the [Twilio Verification SDK](/docs/verify/tutorials/android-sdk-integration) integration guides

For the full flow to be implemented, you must deploy your own JWT provider. The service will receive phone numbers and return signed JWTs, using your `AUTHY_API_KEY` as encoding key.

First, we'll integrate the SDK against a sample backend that we've already set up for you.

## Step 1: Deploy a sample backend to begin the integration

To begin, add a call to the sample token server, which you can deploy with one click from the [GitHub repository](https://github.com/authy/authy-sdk-backend).

Then set your `AUTHY_API_KEY` and your `APP_ID` in the Heroku app as environment variables.

Note:

* If you need help finding your AUTHY\_API\_KEY, please [follow these steps](/docs/authy/twilioauth-sdk/quickstart/obtaining-authy-api-key)
* If you need help finding your APP\_ID, please [follow these steps](/docs/authy/obtain-your-app-id)

![Deploy Authy SDK Backend with options for app name and runtime selection.](https://docs-resources.prod.twilio.com/7e480f1b781473e835c713bae8453cad30a02a16819ccf7098c95c7d7cf3011b.gif)

### Environment after configuration

![Config variables setup with APP\_ID, AUTHY\_API\_KEY, LANG, and RACK\_ENV fields.](https://docs-resources.prod.twilio.com/081e8aa9dd1c5f6da6e0bf72eb123fdf60dfa27467b41ecbe6d7bd57c18e4ba8.png)

## Step 2: Query your sample token server to transform phone numbers into JWTs

Create a new blank-activity project in Android Studio. This example uses Retrofit.

```bash title="Build.gradle"
    compile 'com.squareup.retrofit2:retrofit:2.2.0'
    compile 'com.squareup.retrofit2:converter-gson:2.2.0'
```

Retrofit interface: `TokenServerApi.java`

```java title="TokenServerApi.java"
public interface {
    @POST("/verify/token")
    @FormUrlEncoded
    Call<TokenServerResponse> getToken(@Field("phone_number") String phoneNumber);
}
```

Response holder: `TokenServerResponse.java`

```java title="TokenServerResponse.java"
public class TokenServerResponse {
    @SerializedName("jwt_token")
    private String jwtToken;

    public String getJwtToken() {
        return jwtToken;
    }

    public void setJwtToken(String jwtToken) {
        this.jwtToken = jwtToken;
    }
}
```

In the main activity initialize the service. Replace the `TOKEN_SERVER_URL` string with your deployed sample backend.

```java
    private TokenServerApi tokenServerApi;

    private void initTokenServerApi() {
        String TOKEN_SERVER_URL = "https://verification-token.herokuapp.com";

        Retrofit retrofit = new Retrofit.Builder()
            .addConverterFactory(GsonConverterFactory.create())
            .baseUrl(TOKEN_SERVER_URL)
            .build();

        tokenServerApi = retrofit.create(TokenServerApi.class);
    }
```

Make the call to the sample token server.
This server will receive a phone number and return a JWT which will be used to verify the authenticity of the requester.

```java
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String numberToVerify = "1555555555"; //Should come from user input

            tokenServerApi
                .getToken(numberToVerify)
                .enqueue(new Callback<TokenServerResponse>() {

                @Override
                public void onResponse(Call<TokenServerResponse> call,
                                       Response<TokenServerResponse> response) {
                    String jwtToken = response.body().getJwtToken();
                }

                @Override
                public void onFailure(Call<TokenServerResponse> call, Throwable t) {
                    throw new RuntimeExecutionException(t); //Woops!
                }
            });
        }
    });
```

## Step 3: Add the Twilio Verification SDK for Android

Add the SDK to your module's `build.gradle`:

```bash title="Module build.gradle"
    compile 'com.twilio:verification:+'
```

Note: The SDK is exposed via the jCenter repository, so add that repository to your repository list in your app's `build.gradle`:

```bash title="App build.gradle"
allprojects {
    repositories {
        jcenter()
        (...)
    }
}
```

Create a TwilioVerification instance. Keep a reference in your activity or presenter

```java
    private TwilioVerification twilioVerification;
```

Instantiate it in onCreate(). The constructor will require a context.

```java
    twilioVerification = new TwilioVerification(this);
```

Add the start verification call when JWT is received

```java
public void onResponse(Call<TokenServerResponse> call,
                       Response<TokenServerResponse> response) {
    String jwtToken = response.body().getJwtToken();
    twilioVerification.startVerification(jwtToken, Via.SMS);
}
```

## Step 4: Receive the TwilioVerification callback

When the user's device receives a phone verification SMS from Twilio, Google Play services will automatically pass it to Twilio Verification SDK for validation.
This will let your app know when the SDK has a response.

`AndroidManifest.xml` (inside the `<application>` tag):

```xml title="AndroidManifest.xml"
    <receiver android:name=".MyVerificationReceiver" >
        <intent-filter>
            <action android:name="com.twilio.verification.current_status" />
        </intent-filter>
    </receiver>
```

`MyVerificationReceiver.java`

```java title="MyVerificationReceiver.java"
    public class MyVerificationReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            VerificationStatus verificationStatus = TwilioVerification.getVerificationStatus(intent);

            // NOT_STARTED, STARTED, AWAITING_VERIFICATION, SUCCESS, ERROR
            state = VerificationStatus.State
    }
}
```

## Next step

[Integrate Twilio Verification with your own backend](/docs/verify/tutorials/android-sdk-integration-custom-backend).
