简体   繁体   中英

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

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

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.

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 .

If you want to do this without your kid's knowledge,you can check for the apps installed in his/her phone from time to time and uninstall the unwanted ones. Refer the accepted answer in Install apps silently, with granted INSTALL_PACKAGES permission . You should have your app signed with the device system certificate.

Yes it is possible to do that programatically.from the below code you can do it using an intent. Install APK :

 Intent intent = new Intent(Intent.ACTION_VIEW);
 intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
 startActivity(intent);

Uninstall APK :

 Intent intent = new Intent(Intent.ACTION_DELETE, Uri.fromParts("package",
 getPackageManager().getPackageArchiveInfo(apkUri.getPath(), 0).packageName,null));
 startActivity(intent);

Hope it will help you.Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM