Kiosk mode in Android
Asked Answered
C

11

121

I'm in the process of evaluating if and how a CF .NET enterprise application can be ported to run on Android devices. The application on Windows Mobile phones are run in kiosk mode where the application autostart in fullscreen-mode after booting and with the users unable to accidentally or willingly access any other parts of the phone.

Is it possible on Android to have only one application autostart after booting and prevent users from accidentally (or willingly) access any other parts of the Android device?

Cassandra answered 14/1, 2010 at 22:40 Comment(4)
Do you solve ur problem ?Wharfage
Yes, it is possible. I created a (very) long blog post about this: andreas-schrade.de/2015/02/16/…Transubstantiation
I've also created a blog post about this (partially) using Lollipop - it excludes the boot receiver part though: sureshjoshi.com/mobile/android-kiosk-mode-without-rootArthrospore
I answered a similar question here on different methods to create locked-down single-use devices: https://mcmap.net/q/182812/-android-how-to-make-device-run-only-one-appLp
R
31

You can autostart applications on boot by listening to the android.intent.action.BOOT_COMPLETED intent in a BroadcastReceiver and start your Activity from there. In the Activity you can register yourself as the new default homescreen[1] and handle the keys.

I think there are some instances that you can't handle without modifying the framework (like longpress on Home to show currently active Applications) - I could also be mistaken though.

But for a prototype that could be sufficient.

Have fun tinkering!

[1]:

<intent-filter>
 <action android:name="android.intent.action.MAIN" />
 <category android:name="android.intent.category.HOME" />
 <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Rigobertorigor answered 15/1, 2010 at 11:56 Comment(4)
You also need override the onbackpressed of first acitivty else when you press the back button you go to the launcherGoalie
How to achieve system dialog n notification bars disabled through codeIma
@GnanamR : check my answer at : https://mcmap.net/q/182813/-hide-tablet-system-barWords
@Rinkalkumar Run the app in full-screen mode.Allix
T
18

You could customise this (disable access to menu, limit application addition etc) to enable kiosk. http://code.google.com/p/android-launcher-plus/

Terms answered 25/4, 2012 at 11:49 Comment(6)
Could i know why this was downvoted ? I wrote my full fledged, currently deployed Android kiosk app by editing & developing on top of android launcher plus.Terms
In which case, I upvote both your answer and your comment ;-)Flavopurpurin
@Terms how did you do that? I've been trying to build a kiosk application for ages, and I've solved nearly everything else except for making sure the notifications tray doesn't open.Indoors
@Indoors I think i was looking for onwindowchanged or some similar event (which can possibly indicate Notification Tray opening) and close the tray. I did it a long while ago, so don't remember the specifics.Terms
@Indoors : check my answer at : https://mcmap.net/q/182813/-hide-tablet-system-barWords
I've found a paid solution which is able to provide KIOSK mode even in a not-rooted device. link any better solutions?Jocundity
E
18

In the new Android L Preview, Google has announced Task Locking, which does exactly that. It does seem to need root however.

The L Developer Preview introduces a new task locking API that lets you temporarily restrict users from leaving your app or being interrupted by notifications. This could be used, for example, if you are developing an education app to support high stakes assessment requirements on Android. Once your app activates this mode, users will not be able to see notifications, access other apps, or return to the Home screen, until your app exits the mode.

To prevent unauthorized usage, only authorized apps can activate task locking. Furthermore, task locking authorization must be granted by a specially-configured device owner app, through the android.app.admin.DevicePolicyManager.setLockTaskComponents() method.

To set up a device owner, follow these steps:

  • Attach a device running an Android userdebug build to your development machine.
  • Install your device owner app.
  • Create a device_owner.xml file and save it to the /data/system directory on the device.
$ adb root
$ adb shell stop
$ rm /tmp/device_owner.xml
$ echo "<?xml version='1.0' encoding='utf-8' standalone='yes' ?>" >> /tmp/device_owner.xml
$ echo "&device-owner package=\"<your_device_owner_package>\" name=\"*<your_organization_name>\" />" >> /tmp/device_owner.xml
$ adb push /tmp/device_owner.xml /data/system/device_owner.xml
$ adb reboot

Before using the task locking API in your app, verify that your activity is authorized by calling DevicePolicyManager.isLockTaskPermitted().

To activate task locking, call android.app.Activity.startLockTask() from your authorized activity.

When task locking is active, the following behavior takes effect:

  • The status bar is blank, and user notifications and status information is hidden.
  • The Home and Recent Apps buttons are hidden.
  • Other apps may not launch new activities.
  • The current app may start new activities, as long as doing so does not create new tasks.
  • The user remains locked on your app until an authorized activity calls Activity.stopLockTask().
Ebeneser answered 2/7, 2014 at 20:1 Comment(3)
developer.android.com/guide/topics/admin/device-admin.html - on deploying a Device Admin App.Cort
Here is my article about Task Locks with full setup algoritm pvolan.blogspot.ru/2017/01/android-50-kiosk-mode-aka-super.htmlSarita
For future visitors: Device Owner does NOT require root. You may provision one app as the Device Owner as long as there are not any currently active accounts on the device (Google, Samsung, or otherwise). Once all accounts are removed, you may follow these instructions: baldapps.altervista.org/deviceowner.html Futhermore, Device Owner may also be configured during Android Setup provisioning using a special QR code. More details here: https://mcmap.net/q/182814/-qr-code-provisioning-into-device-owner-mode-fails and a real-world example: alliancex.org/shield/device-owner-qr-setup Enjoy!Impermanent
S
9

After searching for this for a while I've come up with a good solution. This only works on rooted devices though, but I guess if it's just for this one app then rooting it shouldn't be a problem.

Also check out http://thebitplague.wordpress.com/2013/04/05/kiosk-mode-on-the-nexus-7/ for another way

Struma answered 2/8, 2013 at 12:15 Comment(0)
S
5

Starting your app on boot

the BEST way to accomplish this is setting your app as the launcher

<activity ...
  android:launchMode="singleInstance"
  android:windowActionBar="false">
    <intent-filter>
      <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.HOME" />
      <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

Locking your app

the most reliable way is to use a device with Lollipop or greater and make use of

startLockTask

first you must set your app as the device owner. NB your device must be unprovisioned: if you registered it you should do a factory reset and skip the account registration.

to be able to register your app you must first setup a DeviceAdminReceiver component:

package com.example.myapp;

public class MyDeviceAdminReceiver extends android.app.admin.DeviceAdminReceiver {
    @Override
    public void onEnabled(Context context, Intent intent) {
        Toast.makeText(context, "Device admin permission received", Toast.LENGTH_SHORT).show();
    }

    @Override
    public CharSequence onDisableRequested(Context context, Intent intent) {
        return "are you sure?";
    }

    @Override
    public void onDisabled(Context context, Intent intent) {
        Toast.makeText(context, "Device admin permission revoked", Toast.LENGTH_SHORT).show();
    }


    @Override
    public void onLockTaskModeExiting(Context context, Intent intent) {
        // here you must re-lock your app. make your activity know of this event and make it call startLockTask again!
    }
}

once you have an unprovisioned device you can launch the following command from adb (no root required)

adb shell dpm set-device-owner com.example.myapp/.MyDeviceAdminReceiver

to avoid android asking the user permissions to pin your app you must call setLockTaskPackages

finally!

@Override
public void onResume(){
    super.onResume();
    DevicePolicyManager mDevicePolicyManager = (DevicePolicyManager) getSystemService(
            Context.DEVICE_POLICY_SERVICE);
    ComponentName mAdminComponentName = new ComponentName(getApplicationContext(), MyDeviceAdminReceiver.class);
    mDevicePolicyManager.setLockTaskPackages(mAdminComponentName, new String[]{getPackageName()});
    startLockTask();
}
@Override
public void finish(){
    stopLockTask();
    super.finish();
}
Silverside answered 27/7, 2016 at 8:36 Comment(1)
Does this still works with Android 12?Tragedienne
I
5

Google recently released the Android Management API which allows to easily set up kiosk mode for any Android devices running Android 5.1 or above, and also to set various other policies.

Impuissant answered 15/9, 2017 at 7:38 Comment(1)
Awesome find. Here's a direct link to Kiosk mode info: developers.google.com/android/management/policies/…Polydactyl
D
4

Set up Single-Purpose Devices Page of android developer have described this things you can easily get to know more things from there.

Now it is easy to configure Android 6.0 Marshmallow and later devices as corporate-owned, single-use (COSU) devices.

Delusion answered 3/10, 2016 at 12:46 Comment(0)
D
2

Found another possible technique in this forum post. Quoting that post:

http://www.basic4ppc.com/forum/basic4android-getting-started-tutorials/10839-android-kiosk-mode-tutorial.html

Using the following methods you can build an application that will prevent "regular" users from playing with anything other than your application.

The application is made of two modules. The main activity and a service. The service is configured to start at boot. When the service is started it checks if the activity is running or not. If it is not running it uses a timer to start the main activity.

When the activity is paused it schedules the service to start in one second: Code:

Sub Activity_Pause (UserClosed As Boolean)
    If kiosk Then StartServiceAt(KioskService, DateTime.Now + 1 * DateTime.TicksPerSecond, false)    
End Sub

If the user presses on the home screen, the home screen will appear for several seconds. However your application will return to the front after a few seconds and the user will not be able to interact with any other applications or change the settings.

The service is set to be a foreground service. This prevents Android from killing our service. Press on the Stop button to deactivate kiosk mode.

There appears to be an example kiosk-mode code ZIP file available for download, too.

Dacha answered 1/2, 2012 at 22:6 Comment(0)
B
2

Xposed framework can do this. It needs root and there is a possibility that it won't work on every and all platforms. Look for disable() method in class android.app.StatusBarManager.

Here in Android source code

Look here on how to write your own module: Xposed development tutorial

It's much easier than you think at first glance. Good Luck!

Belia answered 20/8, 2015 at 8:2 Comment(1)
Any Xposed module that you think does this?Memling
B
0

Along with setting up your application with a BOOT receiver, and this answer for preventing status bar expansion, this solution works on 4.4 and above as a complete kiosk app :

Place in your onCreate():

    final View view = (View) findViewById(android.R.id.content);
    if (view != null) {
        //"hides" back, home and return button on screen. 
        view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE |
                                   View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
                                   View.SYSTEM_UI_FLAG_IMMERSIVE |
                                   View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
                                   View.SYSTEM_UI_FLAG_FULLSCREEN);
        view.setOnSystemUiVisibilityChangeListener
                (new View.OnSystemUiVisibilityChangeListener() {
                    @Override
                    public void onSystemUiVisibilityChange(int visibility) {
                        // Note that system bars will only be "visible" if none of the
                        // LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
                        if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                            view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE |
                                    View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
                                    View.SYSTEM_UI_FLAG_IMMERSIVE |
                                    View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
                                    View.SYSTEM_UI_FLAG_FULLSCREEN);
                        }
                    }
                });
    }

This will completely hide the back button, apps and home button.

Baugher answered 25/3, 2016 at 18:5 Comment(1)
what about notification bar ?Caddy
H
0

Kiosk mode is nothing but locking a single or set of applications when you switch on an android device. This can be achieved by lock task mode. When the device runs in lock task mode, users typically can’t see notifications, access non-whitelisted apps, or return to the home screen.

The Device policy controller (DPC) can whitelist the app that can run when the system is in lock task mode. Since its a dedicated device for a specific purpose the person using the device can't leave lock task mode. The device which are Android 5.0 and higher can run in lock task mode.

    •        Whitelisting the applications

First step is to whitelist the application by DPC. DPC can whitelist the apps which can be used in lock task mode by calling

DevicePolicyManager.setLockTaskPackages()

    ▪         Start lock task mode

Once the whitelisting is done, DPC can call the below function to start the lock task.

ActivityOptions.setLockTaskEnabled()

You can find more details regarding the lock task mode here. https://developer.android.com/work/dpc/dedicated-devices/lock-task-mode

Hevesy answered 8/9, 2020 at 10:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.