有什么特别的方法可以让系统卸载弹出窗口出现在 android 中的侦听器

Is there any particular way to get the system uninstall popup appears listener in android

我遇到了有关如何获取设备卸载对话框侦听器的问题,如下所示, "Do you want to uninstall this app?" 为此,我尝试使用设备管理员管理器,但没有得到所需的解决方案。如果您能提供任何帮助,我们将不胜感激。

如果你想阻止用户卸载你的应用,你可以注册为Device Admin to prevent the uninstalls (users have to unregister to be able to uninstall your app), 's an example on how to do that, from there I suppose you can restrict the opening of the Android Settings app (users have to open to unregister your app as Device Admin), here的方法,设置应用包名为com.android.settings.


关于如何检测应用程序卸载的第二个答案:

恐怕没有官方的方法来检测卸载弹出窗口,即使你有设备管理员权限,但有一种 hacky 方法可以做到这一点,检查一下 here,它不是完美但有限制,但总比没有好。


如何提示卸载应用的原回答:

你不需要设备管理员管理器的东西来提示卸载你的应用程序,你可以简单地使用一个意图来启动你要求的卸载提示,如下所示:

Uri packageUri = Uri.parse("package:APP_PACKAGE_NAME");
Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageUri);
startActivity(uninstallIntent);

注意:上面的意图ACTION_UNINSTALL_PACKAGE is only available after API 14 (Android 4.0), if your app targets Android P and above, you have to add the permission REQUEST_DELETE_PACKAGE to your AndroidManifest. Also, this intent is deprecated since Android Q, in which situation you should use PackageInstaller.uninstall()是这样的:

String packageName = "com.your.app.package";
Intent intent = new Intent(getActivity(), getActivity().getClass());
PendingIntent sender = PendingIntent.getActivity(getActivity(), 0, intent, 0);
PackageInstaller packageInstaller = getActivity().getPackageManager().getPackageInstaller();
packageInstaller.uninstall(packageName, sender.getIntentSender());

虽然有一大堆限制,详情请参阅 documentation