Android Tutorial Android "Kiosk mode" tutorial

Erel

Administrator
Staff member
Licensed User
Edit: A better kiosk implementation is available: https://www.b4x.com/android/forum/threads/device-owner-tasklock-kiosk-apps-2017.81765/#post-518018

Kiosk mode applications are applications that lock the device and do not allow the user to run any other application other than the kiosk application.

Android doesn't allow true kiosk mode without building a custom ROM.
However 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:
B4X:
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.
 

Attachments

Last edited:

Erel

Administrator
Staff member
Licensed User
The files in the first post were updated to better save battery power when device is sleeping. Note that Sub Activity_Pause will be raised multiple times when the device power button is pressed as the service tries to resume the activity (Activity_resume will not be called).
 

Cableguy

Expert
Licensed User
I was wondering if something like it would be possible...
I have some questions...
1- Using the "kiosk" as a front-end, is it possible to run other Apps? (I guess that using and intend should do the job?)
2- when one of those apps is terminated, is the "Kiosk" Foregrounded immediatly?
3- Is it possible to set restricions of usage in some "services", like web access, Market, etc?
 

Erel

Administrator
Staff member
Licensed User
You will be able to run other applications however the main activity will then autoresume itself. Making it nonfunctional.
 

Cableguy

Expert
Licensed User
No woraround this?...

Using a Service module, would I go on restricting access to the device settings and apps?
 

Erel

Administrator
Staff member
Licensed User
The code in the first post will disable device settings and all other applications. It is not possible using this code to allow some applications and restrict others.
 

peacemaker

Well-Known Member
Licensed User
Pressing HOME and then going to applications....no problem in emulator.
I mean - does not return to Main activity.
 

peacemaker

Well-Known Member
Licensed User
Tested. Almost OK, but .... HOME button and then SETTINGS menu (system settings where applications can be stopped) - is not blocked :-(
On real device, sure.
If to go back from SETTINGS - Main activity again OK.
 

DKCERT

Member
Licensed User
Tested. Almost OK, but .... HOME button and then SETTINGS menu (system settings where applications can be stopped) - is not blocked :-(
On real device, sure.
If to go back from SETTINGS - Main activity again OK.
Form a security point of view this is good! If true kiosk mode was possible a mobile botnet would be up and running in no-time!
 

AscySoft

Active Member
Licensed User
Imagine that I put an kiosk app on a phone running android; then someone calls you. Could I answer the phone? If not, how could I circumvent this?
 

Erel

Administrator
Staff member
Licensed User
The purpose of limitNumberOfTicks is to pause the timer when the device goes to sleep. Otherwise when the user presses on the power button the timer will continue ticking and sending StartActivity messages until the CPU is paused. This variable pauses the timer after one second.
 

ribber

Member
Licensed User
Great tutorial Erel! Very helpful!

One question. If I press the home button on my galaxy s II the kiosk mode needs 4-5 seconds to bring the activity in foreground. Is it possible reduce this time period?

Thank you!
 

Erel

Administrator
Staff member
Licensed User
The service is scheduled to run 1 second after the activity is paused. You can try reducing it to 200ms. It may save 800ms.
 
Top