简体   繁体   English

如何以编程方式阻止Android中应用程序的安装/卸载?

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

Is it possible to programmatically prevent install/uninstall of applications in android? 是否可以以编程方式阻止android中应用程序的安装/卸载? If it possible how can i do this for my Kids application.I could not obtain a helpful answer.Any help much appreciating. 如果可能的话,如何为我的Kids应用程序执行此操作。我无法获得有用的答案。任何帮助我都非常感谢。

Thanks in Advance 提前致谢

there is no API to do such thing 没有API可以做这样的事情

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. Android-创建自定义启动器 ,并以此限制用户查看或仅执行所需的操作。 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. 隐藏状态栏有点棘手,并且需要运行linux命令。 for example, in honeycomb you can do it like that - http://android.serverbox.ch/?p=306 例如,在蜂窝中,您可以这样做-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 . stock-rom随附的内置默认启动器没有提供此功能,但是我敢肯定,您可以在Google Play中找到一些提供此类功能的自定义启动器。 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. 作为Android开发人员,如果没有人开发这样的启动器,我会感到非常惊讶,因为对于开发启动器应用程序的人来说,这是非常简单的开发功能。

Starting from Android Lollipop (5), DevicePolicyManager APIs allow a profile owner admin or a device owner admin to hide and block-uninstall managed applications. 从Android Lollipop(5)开始, DevicePolicyManager API允许配置文件所有者管理员或设备所有者管理员隐藏和阻止卸载托管应用程序。 After provisioning your admin application to be a profile owner or device owner, use the following APIs: 在将您的管理应用程序设置为配置文件所有者或设备所有者之后,请使用以下API:

  • setUninstallBlocked : This allows to define a package name that can't be removed from the device. setUninstallBlocked :这允许定义无法从设备中删除的软件包名称。 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. setApplicationHidden :这允许定义一个软件包名称,该名称将被隐藏,这意味着它将被完全禁用,并且将从启动器中消失。 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). 如果是个人资料所有者管理员,则这两个API仅适用于个人资料托管的即时应用程序(设置工作个人资料后,大多数应用程序都会被克隆并具有2个实例-用户即时和个人资料即时)。


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 . 通过直接调用IPackageManager接口 ,共享系统uid( android:sharedUserId =“ android.uid.system” )的系统应用程序可以使用相同的功能,而无需成为配置文件/设备所有者。

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 . 授予INSTALL_PACKAGES权限,以静默方式安装应用程序中的已接受答案。 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 : 安装APK:

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

Uninstall APK : 卸载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. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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