Expand Minimize Picture-in-picture Power Device Status Voice Recognition Skip Back Skip Forward Minus Plus Play Search
Internet Explorer alert
This browser is not recommended for use with smartdevicelink.com, and may not function properly. Upgrade to a different browser to guarantee support of all features.
close alert
To Top Created with Sketch. To Top
To Bottom Created with Sketch. To Bottom
Android Guides
Adding the Lock Screen

Adding the Lock Screen

The lock screen is a vital part of your SDL app because it prevents the user from using the phone while the vehicle is in motion. SDL takes care of the lock screen for you. If you prefer your own look, but still want the recommended logic that SDL provides for free, you can also set your own custom lock screen.

Configure the Lock Screen Activity

You must declare the SDLLockScreenActivity in your manifest. To do so, simply add the following to your app's AndroidManifest.xml if you have not already done so:

<activity android:name="com.smartdevicelink.managers.lockscreen.SDLLockScreenActivity"
                  android:launchMode="singleTop"/>
Must

This manifest entry must be added for the lock screen feature to work.

Using the Provided Lock Screen

If you have implemented the SdlManager and defined the SDLLockScreenActivity in your manifest, you have a working default lockscreen configuration.
Generic Lock Screen

Customizing the Default Lock Screen

It is possible to customize the background color and app icon in the default provided lockscreen. If you choose not to set your own app icon the library will use the SDL logo.

When customizing your lock screen please define a LockScreenConfig and set it using the builder for your SdlManager.

LockScreenConfig lockScreenConfig = new LockScreenConfig();
builder.setLockScreenConfig(lockScreenConfig);

Custom Lock Screen

Custom Background Color

lockScreenConfig.setBackgroundColor(resourceColor); // For example, getResources().getColor(R.color.black) or Color.parseColor("#000000");

Custom App Icon

lockScreenConfig.setAppIcon(appIconInt); // For example, R.drawable.lockscreen icon

The default lock screen handles retrieving and setting the OEM logo from head units that support this feature.

Custom Lock Screen

This feature can be disabled on the default lock screen by setting showDeviceLogo to false.

lockScreenConfig.showDeviceLogo(false);

Creating a Custom Lock Screen

If you would like to use your own lock screen instead of the one provided by the library, but still use the logic we provide, you can use a new initializer within LockScreenConfig.

lockScreenConfig.setCustomView(customViewInt);

Customizing the Lock Screen State

In SDL Android v4.10, a new parameter displayMode has been added to the LockScreenConfig to control the state of the lock screen and the older boolean parameters have been deprecated.

DisplayMode Description
never The lock screen should never be shown. This should almost always mean that you will build your own lock screen
requiredOnly The lock screen should only be shown when it is required by the head unit
optionalOrRequired The lock screen should be shown when required by the head unit or when the head unit says that its optional, but not in other cases, such as before the user has interacted with your app on the head unit
always The lock screen should always be shown after connection

Disabling the Lock Screen

Please note that a lock screen will be required by most OEMs. You can disable the lock screen manager, but you will then be required to implement your own logic for showing and hiding the lock screen. This is not recommended as the LockScreenConfig adheres to most OEM lock screen requirements. However, if you must create a lock screen manager from scratch, the library's lock screen manager can be disabled via the LockScreenConfig as follows:

LockScreenConfig lockScreenConfig = new LockScreenConfig();
lockScreenConfig.setDisplayMode(LockScreenConfig.DISPLAY_MODE_NEVER);

Making the Lock Screen Always On

The lock screen manager is configured to dismiss the lock screen when it is safe to do so. To always have the lock screen visible when the device is connected to the head unit, simply update the lock screen configuration.

LockScreenConfig lockScreenConfig = new LockScreenConfig();
lockScreenConfig.setDisplayMode(LockScreenConfig.DISPLAY_MODE_ALWAYS);

Enabling User Lockscreen Dismissal (Passenger Mode)

Starting in RPC v6.0+ users may now have the ability to dismiss the lock screen by swiping the lock screen down. Not all OEMs support this new feature. A dismissible lock screen is enabled by default if the head unit enables the feature, but you can disable it manually as well.

Custom Lock Screen

To disable this feature, set LockScreenConfigs enableDismissGesture to false.

LockScreenConfig lockScreenConfig = new LockScreenConfig();
lockScreenConfig.enableDismissGesture(false);
View on GitHub.com
Previous Section Next Section