I want to build an app for android and ensure that the user can only use this app. (i.e. user should not be able to open or install any other app.)
Is it possible to force such restrictions on an Android device ? And if it is where should I start ?
What you are looking for is called the "kiosk mode" (just to help you googling the appropriate term).
There is no such thing in the standard android api (at least... not yet : see the Edit). User always have the ability to press the home button to come back to the Home application.
But solutions exists:
- Writing an Home app
This solution is a little weak (but may fit your requirements ?) : develop a "Home application" (it's very easy : just put something like this in your manifest :
<activity android:name="MyCustomHome"
<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>
</activity>
With this, when the user press the home button : he will have to choose the Home app to use, and if the user decide to make your app it's default Home : he will always came back to your app when pressing the Home button.
Drawback : the Home button is not the only way to get out of the current app, and so this solution won't really block the user (for instance : on samsung, swipe from top to bottom always display the toolbar... and the user can do anything from there)
Using specific constructor extensions :
- samsung-knox is a solution for recent samsung devices (warning : it's a huge and complex security solution for enterprises : many components to do many things and I think you need to be a samsung partner to get acces to kiosk-mode api)
- for motorola : there is an app called EnterpriseHomeScreen that can be used to run your own app in kiosk-mode
I guess other solutions exists for other constructors, but I'm not aware of them.
EDIT/UPDATE
With Android-5.0-Lollipop : the screen pinning api allows you to run your app in kiosk-mode. The android terminology for kiosk-mode is screen-pinning-mode.
To make your app working in screen-pinning-mode, you must use Activity.startLockTask (and Activity.stopLockTask() to quit the screen-pinning mode).
By default the user must approve the screen-pinning-mode (a popup will be prompted when your app call startLockTask
).
If your app is a device owner : then the user won't be prompted and your can go in screen-pinning-mode without confirmation.
The user can also enable screen-pinning-mode for an app manually by choosing : Settings > Security > Screen Pinning. (in this case: the user can exit screen-pinning-mode by holding both the Back and Recent buttons)
Set up Single-Purpose Devices Page of android developer have described this things you can easily get to know more things from there.
来源:https://stackoverflow.com/questions/26371607/how-to-build-software-limiting-user-action-to-one-single-app-on-android