简体   繁体   English

如何卸载我自己的Android应用程序而无需用户干预?

[英]How to uninstall my own Android application without user intervention?

The only way I know of for uninstalling an application is by sending an intent ( as described here ), but this opens an activity for the user to confirm the uninstall. 我知道卸载应用程序的唯一方法是发送一个intent( 如此处所述 ),但这会打开一个活动供用户确认卸载。

I'm aware of the fact that there's no other way to uninstall other applications without user intervention (unless you have the DELETE_PACKAGES permission, which means you are the OEM). 我知道没有其他方法可以在没有用户干预的情况下卸载其他应用程序(除非您拥有DELETE_PACKAGES权限,这意味着您是OEM)。

But, is there a way to uninstall my own application without user intervention? 但是,有没有办法在没有用户干预的情况下卸载我自己的应用程序?

There is a hidden function in PackageManager named deletePackage (it can be called via reflection). PackageManager有一个名为deletePackage的隐藏函数(可以通过反射调用)。 But it requires android.permission.DELETE_PACKAGES permission. 但它需要android.permission.DELETE_PACKAGES权限。 It doesn't matter whether you are the owner of the app or not, you must have this permission granted. 无论您是否是应用程序的所有者,都必须获得此许可。 And this permission will not be granted to 3rd party apps. 此权限不会授予第三方应用。

So, basically, you can't uninstall application even if its yours. 所以,基本上,你不能卸载应用程序,即使它是你的。 This actually makes sense, because user should be in control of such key events as installation and uninstallation of apps. 这实际上是有道理的,因为用户应该控制诸如安装和卸载应用之类的关键事件。 Just imagine the frustration of user if he or she just installed the app from market but cann't find it (or similar scenarios). 想象一下,如果用户刚刚从市场上安装了应用程序但却无法找到它(或类似场景),那么用户会感到沮丧。

You should just disable you application functionality with a proper message. 您应该使用正确的消息禁用应用程序功能。 This will be much more user-friendly. 这将更加用户友好。

App installation and uninstalltion can be silently done if your app is configured as a device owner. 如果您的应用配置为设备所有者,则可以静默完成应用安装和卸载。

Device owner is introduced from android 5.0 onwards. 设备所有者从Android 5.0开始引入。 Silent installation features were added from 6.0 onwards. 从6.0开始添加了静默安装功能。

From andorid source: 来自andorid来源:

if ((mPm.checkUidPermission(android.Manifest.permission.INSTALL_PACKAGES, installerUid)
        == PackageManager.PERMISSION_GRANTED)
        || (installerUid == Process.ROOT_UID)
        || mIsInstallerDeviceOwner) {
    mPermissionsAccepted = true;
} else {
    mPermissionsAccepted = false;
}

This privilege is given to a rooted user, system app and a device owner. 此权限授予root用户,系统应用程序和设备所有者。

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

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