是否可以在Android中以编程方式卸载软件包

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/891141/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 02:29:11  来源:igfitidea点击:

Is it possible to programmatically uninstall a package in Android

android

提问by Will

Can a package uninstall itself? Can a package uninstall another package if they share the same userId and signature?

软件包可以自行卸载吗?如果一个包共享相同的用户 ID 和签名,它们是否可以卸载另一个包?

回答by Robby Lebotha

Hey probably too late but this works for me.

嘿可能为时已晚,但这对我有用。

Uri packageURI = Uri.parse("package:"+"your.packagename.here");
    Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
    startActivity(uninstallIntent);

回答by satur9nine

A 3rd party app cannot install or uninstall any other packages programmatically, that would be a security risk for Android. However a 3rd party app can askthe Android OS to install or uninstall a package using intents, this question should provide more complete information:

第 3 方应用程序无法以编程方式安装或卸载任何其他软件包,这对 Android 来说存在安全风险。但是,第 3 方应用程序可以要求Android 操作系统使用意图安装或卸载软件包,此问题应提供更完整的信息:

install / uninstall APKs programmatically (PackageManager vs Intents)

以编程方式安装/卸载 APK(PackageManager 与 Intents)

回答by Dhruv Kaushal

Third Party app cannot Uninstall App Silently!

第三方应用无法静默卸载应用!

Either you need to become System App to get DELETE_PACKAGESPermission else you need to show Uninstall Popup (User Confirmation)

您需要成为系统应用程序才能获得DELETE_PACKAGES权限,否则您需要显示卸载弹出窗口(用户确认)

Alternatively, you can take Accessibility permission and then by showing an Accessibility Overlay you can tell your service to click on Uninstallbutton! But that will be privacy violation.

或者,您可以获取辅助功能权限,然后通过显示辅助功能覆盖,您可以告诉您的服务单击“卸载”按钮!但这将侵犯隐私。

回答by Louis CAD

In Kotlin, using API 14+, you can just call the following:

在 Kotlin 中,使用 API 14+,您只需调用以下代码:

startActivity(Intent(Intent.ACTION_UNINSTALL_PACKAGE).apply {
     data = Uri.parse("package:$packageName")
})

Or with Android KTX:

或使用 Android KTX:

startActivity(Intent(Intent.ACTION_UNINSTALL_PACKAGE).apply {
     data = "package:$packageName".toUri()
})

It will show the uninstall prompt for your app. You can change packageNameto any package name of another app if needed.

它将显示您的应用程序的卸载提示。packageName如果需要,您可以更改为另一个应用程序的任何包名称。