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:

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?
 

Cableguy

Expert
Licensed User
No woraround this?...

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

peacemaker

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

peacemaker

Expert
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!
 

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!
 
Top