Android Tutorial Android "Kiosk mode" tutorial

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

  • Kiosk.zip
    6.7 KB · Views: 5,763
Last edited:

warwound

Expert
Licensed User
Longtime User
FYO, Android L will have a new API that'll make creation of a kiosk mode app far easier.
It'll be called 'Task Locking', there's some info about it here: http://developer.android.com/preview/api-overview.html#TaskLocking

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.

Anyway, back to the present where we have no such API...

Martin.
 

sanjibnanda

Active Member
Licensed User
Longtime User
2) because I was not able to delete recent task list I worked with
a couple of start activities Start0-Start7
That works very well for me no problems with accidentally activating the
original launcher and a long delay
*

Its an excellent work!
+1
I understood the work flow, except the above part, that why you have created these 7 activities and mentioned them in manifest.
could you spare some time to give more information and its functionality.
 

ilan

Expert
Licensed User
Longtime User
i have not read all posts here so i dont know if my question is already answered, so sorry if it is...

will google allow me to upload such an app?? that will always force my app to come to front?
or could it be that my account will be banned by google?
 

Declan

Well-Known Member
Licensed User
Longtime User
When I run the eaxmple: KioskAppExtended_vc2
I get the following error:
B4A version: 5.20
Parsing code. Error
Error parsing program.
Error description: Unknown type: controls
Are you missing a library reference?
Occurred on line: 39 (Main)
Dim ICS As Controls
at this section of code:
B4X:
    Dim ICS As Controls
    ICS.Initialize(Activity, Me)
 

Declan

Well-Known Member
Licensed User
Longtime User
When I run the eaxmple: KioskAppExtended_vc2
I get the following error:

at this section of code:
B4X:
    Dim ICS As Controls
    ICS.Initialize(Activity, Me)
Ok, sorted.

But now I have another problem - when I run the example KioskAppExtended, it stops unexpectedly.
 

Declan

Well-Known Member
Licensed User
Longtime User
What is KioskAppExtended? Which error do you see in the logs?
It is this example: KioskAppExtended_vc2
https://www.b4x.com/android/forum/threads/android-kiosk-mode-tutorial.10839/page-6#post-176432

I am trying to create a Kiosk type app that is the device owner - the device must operate as a "reader" similar to a "Kindle"
I require no phone functionality (making and receiving calls), but I must have WiFi and data connections to a server.
My app will be the only app that the user has access to.
I am running Android 5.
 

Rusty

Well-Known Member
Licensed User
Longtime User
I have an application that has successfully used Kiosk mode to manage activities and it has worked well for years.
I recently added VoiceRecognition (in the Phone library), which seems to create a new activity.
In managing the many activities within my app, it is obvious how to deal with activities named by me.
What is the activity name for VoiceRecognition?
B4X:
    Select Case Main.LastActivity.tolowercase.trim
        Case "vr"
            If IsPaused(Main) Then KioskTimer.Interval = 1000
        Case "licensecheck"
            If IsPaused(LicenseCheck) Then KioskTimer.Interval = 1000
        Case "checkupdates"
            If IsPaused(CheckUpdates) Then KioskTimer.Interval = 1000
I have the above code segment within my kioskservice which runs its kiosktimer.
Note the first Case. The vr or activity name is what I am looking for so the kiosk manager can handle it.
Thanks,
Rusty
 
Last edited:

Christian321

Member
Licensed User
Longtime User
Hi guys,

I just started programming with B4A and was willing to develop a kids game. Thus, the kiosk mode would be essential as kids seem to always manage to send an application to the backround.

I now have a question that will probably be easy for you to answer: I tried your kiosk example and I figured that it shows the same behavior similar to my approaches. I tried two very simple ways:

(1) Without a service, in my Main activity:
B4X:
Sub Activity_Pause (UserClosed As Boolean)
    StartActivity(Me)    
End Sub

(2) With the Starter service (made sticky) using a 300ms timer:
B4X:
Sub Service_Create
   myWatchdogTimer.Initialize("CheckMainForeground", 300)
   myWatchdogTimer.Enabled = True
End Sub
Sub CheckMainForeground_Tick
    If IsPaused(Main) Then StartActivity(Main)
End Sub

Both ways seem to have the same result. In short, what is the difference to your complex solution?
Many thanks in advance.

Update: I finally managed to get KioskAppExtended running and can see the difference... :cool:
 
Last edited:

Christian321

Member
Licensed User
Longtime User
What is KioskAppExtended?

Hi Erel,

see here: https://www.b4x.com/android/forum/threads/android-kiosk-mode-tutorial.10839/page-5
Post from: mkh42, Jun 19, 2013
Download File KioskAppExtended_vc2.zip

You might need to create the working directory:
B4X:
File.MakeDir(File.DirRootExternal, "Pictures/Screenshots")

I had to find and download quite a lot of required libs. I attached them as Libs.zip.
KioskModeExtended is more like a launcher than an usual kiosk mode app...

Greetings from Germany,
Christian
 

Attachments

  • Libs.zip
    32.7 KB · Views: 524
Last edited:

Sganga61

Member
Licensed User
Longtime User
Hi
I'm using fine the Kiosk service as suggested by Erel. But now, after upgrading to B4A8, it seems like no more usable....

Any suggestion?
 
Top