Use the Samsung SignIn SDK

The Samsung SignIn SDK provides the following capabilities:

  • Check if the device is signed in to a Samsung (optional).
  • Add a Samsung account sign-in button.
  • Start the sign-in flow.
  • Check the execution environment (optional).
  • Establish a user session.
  • Backup and restore the user's record.

Check if the device is signed in to a Samsung account

In your activity's onStart method, you can check if a Samsung account has already signed in on the device.

This task is optional.

// Get the status asynchronously.it returns true or false simply.
samsungSignIn.isSignedIn { isSignedIn ->
    if (isSignedIn) { // already signed in }
    else { // not signed in }
}

Add a "Sign-In with Samsung" button to your app

Add a button in your application's layout to sign in with a Samsung account. Since a standardized button layout is not provided, you can configure it according to the UI of the app.

In the Android activity, register the button's OnClickListener to get the user profile of the Samsung account that is signed in to the device.

Start the sign-in flow

  1. In the activity's onClick() method, create a sign-in intent with the getSignInIntent() method to handle sign-in button taps. Start the intent with ActivityResultLauncher.
override fun onClick(v: View?) {
    when (v?.id) {
        R.id.sign_in_button -> getAccountInfo()
        ...
    }
}

private lateinit var accountLauncher: ActivityResultLauncher<Intent>;

private fun getAccountInfo() {
    try {
        val intent: Intent = samsungSignIn.getSignInIntent()
        accountLauncher.launch(intent)
    } catch (e: ActivityNotFoundException) {
        // TODO: Handle an exception
    }
}
  1. If the Samsung account is NOT signed in on the device, the sign in request window automatically appears. Since sign-in is handled internally, the app does not have to implement requests for login, receiving user input, and handling login results.

  2. Samsung account requires a Disclaimer Agreement for each game. The disclaimer appears only once when the game is launched for the first time. If consent has not been given for the disclaimer, the disclaimer continues to be automatically displayed.

    The information displayed in this window is the project name, a terms and conditions URL, a privacy policy URL, icon, and other information that has been specified in the Samsung account console. Work with your Samsung representative to configure this content.

  3. After the user signs in and agrees to the disclaimer, you can get a SamsungSignInAccount object using getSignedInAccountFromIntent() for the user in the activity's ActivityResultCallback. SamsungSignInAccount contains information about the signed-in user, such as the name, birthdate, email, phone number, and unique user ID.

override fun onCreate(savedInstanceState: Bundle?) {
    accountLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->;
        // In case of an error, it returns null or contains errorCode and errorMessage.
        // account?.errorCode
        // account?.errorMessage
        val account: SamsungSignInAccount? = samsungSignIn.getSignedInAccountFromIntent(result.data)
    }
}

Check the execution environment

If needed, you can check if the app is running on a device (downloaded) or in the cloud (Instant Plays).

// it returns true if the app is running on the cloud.
val isCloud = samsungSignIn.isCloudEnvironment()

Establish a user session

After you get the user profile of the Samsung account that is signed in on the device, check if the user is already in your user database. If so, establish an authenticated session for the user.

If the user isn't in your user database, create a new user record from the information in the SamsungSignInAccount object and establish a session for the user.

Backup and restore the user's record

If you save the authenticated user record in a specific folder, when you register your game in Samsung Galaxy Store Seller Portal, specify all files in this folder path in the User Data Location. The specified files in the folder are backed up and restored when running or reinstalling the game. You can also log in to the game using this information.

For example, if you put the authenticated user record files into the /data/data/{package name}/files folder, enter /data/data/{package name}/files/* in the User Data Location field of Seller Portal.

Figure 1: User Data Location field in Seller Portal