Android Tutorial Device Owner / TaskLock / Kiosk apps 2017

Status
Not open for further replies.
SS-2017-07-18_13.19.46.png


Starting from Android 5 (API 21) there is better support for kiosk applications.
Kiosk applications = applications that the user cannot exit from.
As you can see in this screenshot, the home button and recent apps button are missing. The top notifications drawer is also inaccessible.

This solution is good for devices that serve a specific purpose. For example point of sale solutions or tourist information stands.

Device Owner App

1. The first step is to create an app and provision it as the device owner app. Download the attached example, change its package name to any value you like and run it on the device in Release mode.

2. Connect the device to the PC in USB debug mode. Open command line and run the following command:
Replace your.package.name.here with the correct package name.
B4X:
adb shell dpm set-device-owner your.package.name.here/anywheresoftware.b4a.objects.AdminReceiver2

SS-2017-07-18_14.35.53.png


Existing user accounts on the device must first be removed (Settings - Accounts).

3. Add this code to the manifest editor (it is already there in the example project):
B4X:
AddApplicationText(<receiver android:name="anywheresoftware.b4a.objects.AdminReceiver2"
  android:permission="android.permission.BIND_DEVICE_ADMIN">
  <meta-data android:name="android.app.device_admin"
  android:resource="@xml/device_admin" />
  <intent-filter>
  <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
  </intent-filter>
</receiver>)
CreateResource(xml, device_admin.xml,
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
  <uses-policies>
  <limit-password />
  <reset-password />
  <force-lock />
  </uses-policies>
</device-admin>
)

4. See how the example code locks and unlocks the activity.

Note that for the solution to be more robust it is recommended to make the activity a home launcher activity.

This is done by adding this code to the manifest editor:
B4X:
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" />
</intent-filter>
)

With this code you need to click on the home button once and then you will be asked to choose the home launcher app. Choose your app.
This is important to make sure that your app starts as soon as possible after a restart.
During development you might prefer to disable it.

It depends on Administrator library v1.1+: https://www.b4x.com/android/forum/threads/updates-to-internal-libraries.59340/#post-518017
 

Attachments

  • Kiosk.zip
    8.6 KB · Views: 2,536

Magma

Expert
Licensed User
Longtime User
Hi there...

a. is it possible to load an app from the kiosk app (that actually) will be the foreground service that will load the kiosk app every min (like Erel said).. ? how ?
b. is it possible to load some app like google maps, IGO, Sygic from kiosk app and how ?

Thanks.
 

Magma

Expert
Licensed User
Longtime User
@Erel I ve understand about Intent but my question is someway different...

Actually i want the kiosk app stay alive - so before some posts you said that is better run another app too like a service to run kiosk app... That app will be running before kiosk app ?

Because if it is running after from kiosk app first i must unlock the app and then running the service-sticky-app (will be running the kiosk app)...

So from your post i ve understand will be the second answer - right ?
 

John Decowski

Member
Licensed User
Longtime User
Is there a way with this method to dock your app on the top while launch another app? Reason being I want to Make an app for my motorcycle with a gauge set on top and nav on bottom ie. google or Waze
 
Status
Not open for further replies.
Top