How to programmatically prevent Install/Uninstall of applications in android?

12,613

Solution 1

there is no API to do such thing

but - you can develop your own customized launcher

Android - creating custom launcher, and by that to restrict the user's to see or to do only the things you want. for example - when you implementing the home screen showing all the applications - when you implement the uninstall feature - open some dialog requesting for password..

you will also need to root the device, for implement hiding of the system bar - to prevent the user acess to settings. hiding status bar is a bit tricky, and requires running linux commands. for example, in honeycomb you can do it like that - http://android.serverbox.ch/?p=306

the built-in default launcher coming with the stock-rom don't provide such feature, but I'm sure you can find some custom launcher in the Google Play providing such feature . after installing launcher and restarting the device - you can define him as the default launcher - and by that even if your kids will restart the device - they will have access only to the custom launcher.

as an Android developer, I'll be very surprised if no-one developed such launcher yet, because it's very simple feature for development for someone who develops launcher app.

Solution 2

Starting from Android Lollipop (5), DevicePolicyManager APIs allow a profile owner admin or a device owner admin to hide and block-uninstall managed applications. After provisioning your admin application to be a profile owner or device owner, use the following APIs:

  • setUninstallBlocked: This allows to define a package name that can't be removed from the device. Only the profile/device owner will be able to enable/disable this flag.
  • setApplicationHidden: This allows to define a package name that will be hidden, meaning, it will fully disabled and will be disappear from the launcher. Note that hiding an application will not uninstall it, and the admin can always unhide it and fully restore the app with all its user data.

In the case of a profile owner admin, both APIs will be applicable only to the profile managed instant application (after setting a work profile, most applications are cloned and have 2 instances- user instant and profile instant).


System applications that share the system uid (android:sharedUserId="android.uid.system") are able to use the same functionality without being a profile/device owner by directly calling IPackageManager interfaces.

Share:
12,613
Devu Soman
Author by

Devu Soman

Updated on June 14, 2022

Comments

  • Devu Soman
    Devu Soman almost 2 years

    Is it possible to programmatically prevent install/uninstall of applications in android? If it possible how can i do this for my Kids application.I could not obtain a helpful answer.Any help much appreciating.

    Thanks in Advance