(**Edit:** Updated after some more testing)

Check the [latest documentation](http://developer.android.com/about/versions/android-5.0.html#Enterprise).

This feature seems to be called Screen pinning now, and the App does not have to be the device owner. If the device owner is not set the user will be prompted to accept. But there are issues with this for kiosk use, mentioned below.


    There are two ways to activate screen pinning:
    
    Manually: Users can enable screen pinning in Settings > Security > Screen Pinning, and select the tasks they want to pin by touching the green pin icon in the recents screen.
    Programmatically: To activate screen pinning programmatically, call startLockTask() from your app. If the requesting app is not a device owner, the user is prompted for confirmation. A device owner app can call the setLockTaskPackages() method to enable apps to be pinnable without the user confirmation step.

If you activate screen pinning programatically (non device owner App) or on the device using the pin in the recents you get the following behaviour:

A dialog appears asking the user if they want to enable screen pinning and if they want to require a password to exit. If they press yes the status bar and notifications disappear, back, home and recents buttons do NOT disappear. Tapping on home or recents makes a toast appear inform the user how to exit screen pinning.

The user can then hold down back and recents to exit screen pinning. If the user selected to require a password, they will get kicked straight to the lock screen. This behaviour means it is not suitable for a kiosk imo. As it is too easy for kiosk users to end up looking at the lock screen.

To get a proper kiosk mode we need to set the device owner. Google's documentation says you need to do this with NFC:

    To deploy and activate a device owner, you must perform an NFC data transfer from a programming app to the device while the device is in its unprovisioned state.

Using NFC to do this seems a bit complex (what if a device does not have NFC?). I have not investigated this yet so if anyone can provide info how you go about setting the device owner by NFC?

But if you root a device you can set the device owner as per Google's previous instructions (adding a device_owner.xml) as I mentioned [here](http://stackoverflow.com/questions/26358689/how-to-use-android-l-preview-task-locking)

Now you can properly lock the App, no dialog appears for the user to accept, when enabled the recents and home button disappear and the user cannot leave the App unless your App unlocks itself. A proper kiosk mode. I have tested this on a Nexus 7 2013 with the latest Lollipop build.

The following snippet turns on the lock:

    mDPM = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    mDeviceAdminSample = new ComponentName(this, DeviceAdminSample.class);
    
    if (mDPM.isDeviceOwnerApp(this.getPackageName())) {
        Log.d(TAG, "isDeviceOwnerApp: YES");
        String[] packages = {this.getPackageName()};
        mDPM.setLockTaskPackages(mDeviceAdminSample, packages);
    } else {
        Log.d(TAG, "isDeviceOwnerApp: NO");
    }

    if (mDPM.isLockTaskPermitted(this.getPackageName())) {
        Log.d(TAG, "isLockTaskPermitted: ALLOWED");
        startLockTask();
    } else {
        Log.d(TAG, "isLockTaskPermitted: NOT ALLOWED");
    }