简体   繁体   English

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

[英]Is it possible to programmatically uninstall a package in Android

Can a package uninstall itself? 软件包可以自行卸载吗? Can a package uninstall another package if they share the same userId and signature? 如果一个软件包共享相同的userId和签名,是否可以卸载另一个软件包?

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

A 3rd party app cannot install or uninstall any other packages programmatically, that would be a security risk for Android. 第三方应用程序无法以编程方式安装或卸载任何其他软件包,这将对Android构成安全隐患。 However a 3rd party app can ask the Android OS to install or uninstall a package using intents, this question should provide more complete information: 但是,第三方应用程序可以要求 Android OS使用意图安装或卸载软件包,此问题应提供更完整的信息:

install / uninstall APKs programmatically (PackageManager vs Intents) 以编程方式安装/卸载APK(PackageManager与Intents)

Third Party app cannot Uninstall App Silently! 第三方应用程序无法静默卸载应用程序!

Either you need to become System App to get DELETE_PACKAGES Permission else you need to show Uninstall Popup (User Confirmation) 您需要成为System App以获得DELETE_PACKAGES权限,否则您需要显示卸载弹出窗口 (用户确认)

Alternatively, you can take Accessibility permission and then by showing an Accessibility Overlay you can tell your service to click on Uninstall button! 或者,您可以获取“可访问性”权限,然后显示“可访问性覆盖”,可以告诉您的服务单击“ 卸载”按钮! But that will be privacy violation. 但这将侵犯隐私。

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 packageName to any package name of another app if needed. 如果需要,可以将packageName更改为另一个应用程序的任何软件包名称。

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

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