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,726
Last edited:

ZeroSoft

Member
Licensed User
Longtime User
You can add this:
B4X:
<action android:name="android.intent.action.MAIN" />              
<category android:name="android.intent.category.HOME" />                 
<category android:name="android.intent.category.DEFAULT" />               
<category android:name="android.intent.category.MONKEY"/>

to the activity in the manifest, and bind the application too the home key
 

ribber

Member
Licensed User
Longtime User
I've also read about your solution @Zero

But if I bind the application to the home screen I have always to select a launcher for this action. Is there a work around?
 

rbsoft

Active Member
Licensed User
Longtime User
That sounds like an interesting approach.

I am using Erel's Kiosk mode right now. But it takes to long for the app to show again. It gives the user enough time to switch Gps off or put the device into flight mode.

Rolf
 

rbsoft

Active Member
Licensed User
Longtime User
@ZeroSoft

B4X:
<action android:name="android.intent.action.MAIN" />              
<category android:name="android.intent.category.HOME" />                 
<category android:name="android.intent.category.DEFAULT" />               
<category android:name="android.intent.category.MONKEY"/>

How and where exactly would you add this in the Manifest Editor?
Can you post an example?

Rolf
 

rbsoft

Active Member
Licensed User
Longtime User
Ok, got it sorted out. Just needed to add like this in the Manifest Editor.

B4X:
'Kiosk Mode
AddActivityText("main",
   <intent-filter>
   <action android:name="android.intent.action.MAIN" />
   <category android:name="android.intent.category.HOME" />
   <category android:name="android.intent.category.DEFAULT" />
   <category android:name="android.intent.category.MONKEY"/>
   </intent-filter>
)
'End Kiosk Mode

Absolutely great!

Rolf
 

slowtime

Active Member
Licensed User
Longtime User
Hi,

I'd like permit user exit the kiosked application for 5 minutes, but at the end of 5 minutes he must return to kiosked application

Is it correct change in

HTML:
sub Activity_Pause (UserClosed As Boolean)

.... dateTime.Now + 1 

in to 

....dateTime.Now + 300 (60 * 5 minutes)
Must I change other in service module or this change is all I must do.

Thank you for help

Ciao
 

slowtime

Active Member
Licensed User
Longtime User
Hi Erel,

This solutions works
HTML:
Sub Activity_Pause (UserClosed As Boolean)
If KioskService.limitNumberOfTicks >= 10 Then Return 
'If kiosk Then StartServiceAt(KioskService, DateTime.Now + 20 * DateTime.TicksPerSecond, False)

This solutions woks too.
HTML:
Sub Activity_Pause (UserClosed As Boolean)
If KioskService.limitNumberOfTicks >= 10 Then Return 
If kiosk Then StartServiceAt(KioskService, DateTime.Now + 1000 * 60, False)

I'll use Erel solution.

I'm going to implement settings flags in pause and resume so I can set different time of kiosk mode (es user read mail by intent from application, user use another application by intent from main application)

But I can't understand because when main application return by kiosk it is seems like service was called twice. Like 2 instance of the the same application o same service is running togheter.

Thank you for suggestions.

Sorry but English is not my languange.

Ciao
 

slowtime

Active Member
Licensed User
Longtime User
Hello Erel

I set in service module -> Notification.Sound = true

I sometime listened two beep when application exit and then come back by kiosk.

Maybe i wrote in the code something wrong, i'm checking, but kiosk is full useable.
Anyway thank you for kiosk and b4a.
I love ba4, simple and incisive.

Ciao
 

AllanD

Member
Licensed User
Longtime User
Stop The mini apps on Galaxy Tablet

Hello, I am loving this kiosk app but I still have one issue on the Galaxy Tab, and that is how to prevent the "mini apps" at the bottom of the screen from showing.

Does anybody have an idea how to do that?

Thanks,
Allan
 

ykucuk

Well-Known Member
Licensed User
Longtime User
it works but...

Its really work great. but when i click search or home button device return to homescreen for some second and after turn back to kiosk app.

i understand that there is no way disable buttons but is there any chance to set time more less for turn back our app again.

i chance timer 's interval 100 to 10 but notting happened. its stil about 2-3 second.

my device is android 4.0.3

thank you
 

lszomb

New Member
got a noob question: how can I download the attachment? do I need to subscribe first. Second question: can kiosk app suppress incoming call and SMS? thanks
 

lupiana

Member
Licensed User
Longtime User
Delete kiosk

I tried to run the program Kiosk in
emulator.

I only found one bistable Button: STOP and START.

The problem:
are in DEBUG mode, I close the program and create another program.

Launching the new program and when it connects with
the emulator always displays the kiosk and NOT the programa
in activity '.

What can I do to eliminate this inconvenience?

Another problem: I tried to assign
a Private Key and every time I open a new program
give me ERROR not finding the Keystore.

How can I eliminate this Private Key Sign?


Thanks

Lupiana
 

GaNdAlF89

Active Member
Licensed User
Longtime User
KioskService with multiples activity

How I can modify KioskService code to run with multiples activity?

example: I have an activity for login and an activity for menu. From menu I can start others activities.
I want that KioskService doesn't run when menu activity starts, and when others activities start from menu...

(sorry for my bad english!)
 
Last edited:
Top