开发者

How to uninstall my own Android application without user intervention?

开发者 https://www.devze.com 2023-03-13 11:25 出处:网络
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.

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.

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).

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). But it requires android.permission.DELETE_PACKAGES permission. 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. Silent installation features were added from 6.0 onwards.

From andorid source:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号