API Reference

For Android


First time here? Visit the Snap Kit developer portal to add your application, exchange keys, and get set up with the proper API credentials.

The Android Snap Kit SDK provides an API in Java, organized by kit:

  • Creative: Share media, stickers and other metadata to Snapchat.
  • Login: Allow your users to log in using Snapchat credentials and fetch their Bitmoji and identity data.
  • Bitmoji: Add a Bitmoji sticker tray to your app so users can communicate visually.

We recommend trying the getting started guides for Creative Kit, Login Kit, Bitmoji Kit, and Story Kit to get familiar with each. When you're ready to develop Snap Kit functionality in your app, this document provides the Android API components.

We hope you’ll find everything you need. Want to keep up?

Creative Kit


SnapCreative

Description

This top-level module provides the Creative Kit APIs.

Constructor
SnapCreative()
Methods
public static SnapCreativeKitApi getApi(Context context)

Getter method for the SnapCreativeKitApi

  • Parameters

    • context: the activity Context
public static SnapMediaFactory getMediaFactory(Context context)

Getter method for the SnapMediaFactory

  • Parameters

    • context: the activity Context

SnapCreativeKitApi

Description

This is the Creative Kit API module.

Methods
public void send(SnapContent content)

Method to send your SnapContent to Snapchat

  • Parameters

    • content: the SnapContent to be sent to Snapchat
public void sendWithCompletionHandler(SnapContent content, SnapCreativeKitCompletionCallback callback)

Method to send your SnapContent to Snapchat with a completion handler indicating if Snapchat was opened

  • Parameters

    • content: the SnapContent to be sent to Snapchat

    • callback: the SnapCreativeKitCompletionCallback with callbacks when Snapchat is called


SnapCreativeKitCompletionCallback

Description

Callback interface for the CreativeKitApi send method

Methods
void onSendSuccess()

Callback called when the user is successfully directed to Snapchat.

void onSendFailed(SnapCreativeKitSendError error)

Callback called when an error occurs while attempting to share to Snapchat using Creative Kit.

  • Parameters

    • error: the error type when sending to Snapchat fails.

SnapMediaFactory

Description

Use this class to create new media files.

Methods
public SnapVideoFile getSnapVideoFromFile(java.io.File file)

Factory method to create a SnapVideoFile instance given a video file

  • Parameters

    • file: the video file represented as a java.io.File
  • Return value

    • The SnapVideoFile created from the file parameter
  • Throws

    • SnapMediaSizeException: When video file size exceeds 15MB
    • SnapVideoLengthException: When video length exceeds 15 seconds
public SnapPhotoFile getSnapPhotoFromFile(java.io.File file)

Factory method to create a SnapPhotoFile instance given a photo file

  • Parameters

    • file: the photo file represented as a java.io.File
  • Return value

    • The SnapPhotoFile created from the file parameter
  • Throws

    • SnapMediaSizeException: If photo size exceeds 15MB
public SnapSticker getSnapStickerFromFile(java.io.File file)

Factory method to create a SnapSticker instance given a sticker file

  • Parameters

    • file: the sticker file represented as a java.io.File
  • Return value

    • The SnapSticker created from the file parameter
  • Throws

    • SnapStickerSizeException: If sticker size exceeds 1MB

SnapPhotoFile

Description

This model holds a photo file.

Methods
public java.io.File getPhotoFile()

Getter method for the photo file

  • Return value

    • The java.io.File representation of the photo file

SnapPhotoContentExtends SnapContent

Description

This is a model of the SnapContent class for sharing a still image to Snapchat preview.

Constructor
SnapPhotoContent(SnapPhotoFile snapPhotoFile)

Constructor for sharing an image to snapchat

  • Parameters

    • snapPhotoFile: the image for sharing represented as a SnapPhotoFile

SnapVideoContentExtends SnapContent

Description

This is a model of the SnapContent class for sharing video content to Snapchat preview.

Constructor
SnapVideoContent(SnapVideoFile snapVideoFile)

Constructor for sharing video content into Snapchat preview page


SnapSticker

Description

This class holds the sticker data to overlay on the Snap's content.

Methods
public void setRotationDegreesClockwise(float rotation)

Setter method for the rotation to apply on the sticker

  • Parameters

    • rotation: a float representing the degrees that the sticker will be rotated clockwise
public void setPosX(float positionX)

Setter method for the horizontal position of the sticker

  • Parameters

    • positionX: a float in the range of 0-1 representing the horizontal position of the center of the sticker
public void setPosY(float positionY)

Setter method for the vertical position of the sticker

  • Parameters

    • positionY: a float in the range of 0-1 representing the vertical position of the center of the sticker
public void setWidth(float width)

Setter method for the width of the sticker, in pixels

  • Parameters

    • width: a float specifying the width of the sticker in pixels
public void setHeight(float height)

Setter method for the height of the sticker, in pixels

  • Parameters

    • height: a float specifying the height of the sticker in pixels
public java.io.File getStickerFile()

Getter for the sticker file

  • Return value

    • The sticker file as a java.io.File instance

SnapLiveCameraContentExtends SnapContent

Description

This is a model for the SnapContent class. It links into the camera preview for the Snap.

Constructor
SnapLiveCameraContent()

Default constructor for content to share directly into camera page in Snapchat


SnapContent

Description

This is the base SnapContent type. It represents an abstract type that can be shared into Snapchat and contains metadata such as stickers, attachment URL, and caption text properties.

Methods
public setSnapSticker(SnapSticker snapSticker)

Setter method for the sticker to be shared with Snapchat

  • Parameters

    • snapSticker: the SnapSticker instance
public setAttachmentUrl(String attachmentUrl)

Setter method to set the attachment URL to link with the Snap

  • Parameters

    • attachmentUrl: the attachment URL String
public void setCaptionText(String captionText)

Setter method for the caption text to overlay on top of the Snap

  • Parameters

    • captionText: the caption text String to overlay on top of the Snap

Login Kit


SnapLogin

Description

This module handles authentication using Snapchat.

Constructor
SnapLogin()
Methods
public static View getButton(Context context, ViewGroup container)

Method to get a standard login button to authenticate using Snapchat Note: Alternatively, you can use AuthTokenManager directly to start authenticating

  • Parameters

    • context: the activity Context
    • container: the root container ViewGroup which the login button is inflated into and attached to.
  • Return value

    • The login button View
public static LoginStateController getLoginStateController(Context context)

Getter method for the LoginStateController

  • Parameters

    • context: the activity Context
  • Return value

    • the LoginStateController for the login through Snapchat
public static boolean isUserLoggedIn(Context context)

Getter method to know if user is authenticated using Snapchat and has a valid auth token

  • Parameters

    • context: the activity Context
  • Return value

    • True if user is authenticated using Snapchat, False otherwise
public static AuthTokenManager getAuthTokenManager(Context context)

Getter method for the AuthTokenManager

  • Parameters

    • context: the activity Context
  • Return value

    • The AuthTokenManager instance
public static void fetchUserData(Context context,
                                 String query,
                                 String variables,
                                 FetchUserDataCallback callback)

Method to fetch user data based on scopes requested

  • Parameters

    • context: the activity Context
    • query: the GraphQL query to make
    • variables: the variables in the GraphQL query
    • callback: the FetchUserDataCallback for when the data is fetched

FetchUserDataCallback

Description

Interface for fetching user data.

Methods
void onSuccess(UserDataResponse userDataResponse)

Callback when user data is successfully fetched

  • Parameters

    • userDataResponse: the UserDataResponse corresponding to the query
void onFailure(boolean isNetworkError, int statusCode)

Callback for when user data request ended in failure

  • Parameters

    • isNetworkError: True if requested failed due to a network error, False otherwise
    • statusCode: the status code of the response

AuthTokenManager

Description

The module that manages the user’s auth token credentials.

Methods
boolean isUserLoggedIn()

Getter method to know if the AuthTokenManager has a valid auth token for the user

  • Return value

    • true if user has a valid access token, false otherwise
boolean hasAccessToScope(String scope)

Determines whether the user has authorized the current session to have access to resources with the requested scope

  • Parameters

  • Return value

    • true if the current session has access to resources with the scope, false otherwise
void revokeToken()

Method to revoke the user’s current access token and unlink the linked Snapchat account

void startTokenGrant()

The first step of the OAuth flow; begins the authenticating flow using OAuth


LoginStateController

Description

This module provides hooks for callbacks on state changes to login.

Methods
void addOnLoginStateChangedListener(LoginStateController.OnLoginStateChangedListener listener)

Method to add an OnLoginStateChangedListener to the LoginStateController

  • Parameters

    • listener: the OnLoginStateChangedListener instance to be added to the LoginStateController
void removeOnLoginStateChangedListener(LoginStateController.OnLoginStateChangedListener listener)

Method to remove an OnLoginStateChangedListener from the LoginStateController

  • Parameters

    • listener: the OnLoginStateChangedListener instance to be removed from the LoginStateController
void addOnLoginStartListener(LoginStateController.OnLoginStartListener listener)

Method to add an OnLoginStartListener to the LoginStateController

  • Parameters

    • listener: the OnLoginStartListener instance to be added to the LoginStateController
void removeOnLoginStartListener(LoginStateController.OnLoginStartListener listener)

Method to remove an OnLoginStartListener from the LoginStateController

  • Parameters

    • listener: the OnLoginStartListener instance to be removed from the LoginStateController

LoginStateController.OnLoginStartListener

Description

Interface for when the login request has started after the user has confirmed they want to approve the third party for access to the scopes listed.

Methods
void onLoginStart()

Called when the login request has started after the user has confirmed they want to approve the third party for access to the scopes listed


LoginStateController.OnLoginStateChangedListener

Description

Interface for login state change callbacks.

Methods
void onLoginSucceeded()

Called when login through Snapchat has succeeded

void onLoginFailed()

Called when login through Snapchat failed

void onLogout()

Called whenever a user explicitly logs out via revokeToken() or whenever the server returns 401, requiring forced logout

Bitmoji Kit


Bitmoji

Description

This top-level module provides Bitmoji Kit APIs.

Methods
static void fetchAvatarUrl(Context context, FetchAvatarUrlCallback callback)

Makes a network request to fetch the URL for the active user’s Bitmoji avatar icon

  • Parameters

    • context: the activity or application Context
    • callback: the callback that will be invoked after either a successful or a failed network request
  • Example

    Bitmoji.fetchAvatarUrl(context, new FetchAvatarUrlCallback() {
      @Override
      public void onSuccess(@Nullable String avatarUrl) {
          // load the image for the url
      }
    
      @Override
      public void onFailure(boolean isNetworkError, int statusCode) {
          // handle the error
      }
    });

FetchAvatarUrlCallback

Description

This is the callback for Bitmoji avatar URL fetches made by Bitmoji.fetchAvatarUrl.

Methods
void onSuccess(String avatarUrl)

Called after making a successful network request

  • Parameters

    • avatarUrl: the URL of the user’s Bitmoji avatar icon, or null if the user does not have Bitmoji

BitmojiFragmentExtends android.support.v4.app.Fragment

Description

This is the Android Support Library Fragment for the Bitmoji sticker picker.

The FragmentActivity that adds this Fragment must first already implement the OnBitmojiSelectedListener interface. This interface allows the application to be notified whenever a user selects a Bitmoji sticker from the sticker picker.

The FragmentActivity may also optionally implement the OnBitmojiSearchFocusChangeListener interface, which listens for users entering or exiting the search field.

Methods
void setFriend(String friendUserId)

Method to specify a friend user to feature in Bitmojis. The sticker picker will include Bitmojis co-starring the current user and the provided friend user. The friend will only appear if they have granted the app access to their Bitmoji avatar as well.

  • Parameters

    • The friendUserId: the external ID of the friend user provided by the app

OnBitmojiSelectedListener

Description

Your FragmentActivity that adds the BitmojiFragment must implement this interface. This allows the FragmentActivity to be notified whenever a user selects a Bitmoji from the BitmojiFragment.

Methods
void onBitmojiSelected(String imageUrl, Drawable previewDrawable)

Called when the user selects a Bitmoji from the BitmojiFragment

  • Parameters

    • imageUrl: the URL of the selected Bitmoji
    • previewDrawable: a Drawable representing the selected Bitmoji - intended for preview purposes only

OnBitmojiSearchFocusChangeListener

Description

Your FragmentActivity that adds the BitmojiFragment may optionally implement this interface. This allows the FragmentActivity to be notified whenever a user enters or exits the search bar inside the BitmojiFragment.

Methods
void onBitmojiSearchFocusChange(boolean hasFocus)

Called when the user enters or exits the search bar inside the BitmojiFragment

  • Parameters

    • hasFocus: true if the user has entered the search bar, false if the user has exited the search bar

BitmojiIconFragmentExtends android.support.v4.app.Fragment

Description

This is the Android Support Library Fragment for the Bitmoji avatar icon.

The avatar icon is an image of your user that automatically refreshes to display the latest version of their avatar in your app. If the user is not logged in or does not have a Bitmoji, the element simply shows the Bitmoji logo.