Skip to main content

User Authentication

Restrict apps' distribution only for selected users


There are many circumstances in which you would like to restrict apps' distributions to select users for testing.

Apps on Android devices can be extracted by anyone without root privileges simply by enabling Developer Mode. Therefore, restricting file distribution alone is not sufficient to protect your app. Even in such cases, you can use the DeployGate SDK to control authorization for using the app.

For example, entering the following code into Activity#onCreate will prevent unauthorized users from launching apps.

Java
DeployGate.registerCallback(new DeployGateCallback() {
@Override
public void onInitialized(boolean isServiceAvailable) {
if (!isServiceAvailable) {
Toast.makeText(this, "DeployGate is not available", Toast.LENGTH_SHORT).show();
finish();
}
}

@Override
public void onStatusChanged(boolean isManaged, boolean isAuthorized, String loginUsername, boolean isStopped) {
if (!isAuthorized) {
Toast.makeText(this, "This device is not authorized to use this app", Toast.LENGTH_SHORT).show();
finish();
}
}

Additionally, DeployGate SDK provides several functions to check if a user has permission to use an app. For example, it’s possible to see if an app is on the list of apps approved for use by a particular user.

DeployGate.isDeployGateAvailable(); // True if Deploygate has been installed
DeployGate.isAuthorized(); // True if app is available for current user
DeployGate.getLoginUsername(); // Current login username
DeployGate.getAuthorUsername(); // App developer username

See JavaDoc or GitHub - DeployGate/deploygate-android-sdk for details.