0

I'm creating an Android kiosk application, a launcher application. The application shows apps that are allowed to be used by the user. I want to prevent the user from opening unwanted application (like recent apps, settings etc). So I've build a service (KioskService.class) which checks if the active activity is on the list of allowed applications. This is done with a Thread (So it checks even if another applciation is opened)

At this moment when an unallowed application is opened I return the kiosk application. What i want is that the previous activity is reopened.

So for example. When I open the Calender application (which is an allowed application) en then I open the setting from the Notification bar, the application needs to return to de Calender activity.

Thanks in advance,

T

  • Did you ear something about Lollipop "Screen Pinning" (Task Locking) it's perfect to build a Kiosk, take a look at https://stackoverflow.com/questions/26358689/how-to-use-android-l-preview-task-locking and https://stackoverflow.com/questions/21183328/how-to-make-my-app-a-device-owner – vzamanillo Jun 17 '15 at 10:13
  • I did hear about it! I use it in my app. But the app need to work on Android 4.3 and higher! – DevelopingBeaver Jun 17 '15 at 10:27

3 Answers3

2

First you will need root privileges, then try the below steps:

1) run a daemon service to constantly monitor which app is currently used by user. this can be achieved by getting the foreground app's package name. For getting foreground app's package name use this code:

ActivityManager mActivityManager =(ActivityManager)this.getSystemService(Context.ACTIVITY_SERVICE);

if(Build.VERSION.SDK_INT > 20){
String mPackageName = mActivityManager.getRunningAppProcesses().get(0).processName;
}
else{
  String mpackageName = mActivityManager.getRunningTasks(1).get(0).topActivity.getPackageName();
}

2) compare the package to your white list apps. If the current app is not in your list then kill it with the below code:

Process process = Runtime.getRuntime().exec("adb shell am force-stop packagename");
process.waitFor();

3) to prevent user navigating using notification bar or navigation button, you can kill the system UI process and make your own implementation of navigation buttons similar to floating buttons.

Dev shadow
  • 31
  • 4
0

Shutting down other applications may cause a security issue for you.

The Android docs state

Your application runs in a secure sandbox environment, so other processes on the system cannot access your code or private data.

Ergo, trying to shutdown other apps from your own Service may not a viable option.

You could however bring your own app back to the foreground if another app is started?

Edit:

This looks like an interesting tutorial on how to build a kiosk app.

The approach is also interesting, as in your app starts on boot, so doesn't give opportunity for the user to launch another app,

Zain
  • 2,336
  • 1
  • 16
  • 25
0

What @Zain has given is a wonderful tutorial. I have gone through it.

If you want to disable other applications, you can do it with adb shell command.

adb shell pm list packages - will list all packages

and

adb shell pm hide com.the.packagename - will disable any package.

shijin
  • 2,998
  • 1
  • 24
  • 30