I am using this code on Android 10 to silently uninstall a package:
PendingIntent pendingIntent = PendingIntent.GetBroadcast(Android.App.Application.Context, 0, new Intent("ANY_UNIQUE_NAME_WILL_DO"), 0);
Android.App.Application.Context.PackageManager.PackageInstaller.RegisterSessionCallback(this);
Android.App.Application.Context.PackageManager.PackageInstaller.Uninstall(HardCodedApplicationName, pendingIntent.IntentSender);
The uninstall works fine, but I would like to keep the app's data so it will work again after I install an older version. (Actually I would just like to downgrade the app in place, but it seems Android 10 doesn't allow that so this is my next-best idea.)
I see that adb can do an install with the -k option:
adb shell pm uninstall -k com.YOUR_PACKAGE_NAME
so is it possible to do the same with PackageManager.PackageInstaller? I have read hints about the flag DONT_DELETE_DATA, which was renamed to DELETE_KEEP_DATA - but the Uninstall(...) method doesn't accept flags as a parameter. I don't even see a "Delete" package, or at least not via the silent install/uninstall methods.