How can I prevent uninstalling selected applications by mistake? can I add a user application to device administrator for example?
No, you cannot add any app as a device administrator unless it has provisions for it. What you can do is convert those apps as system apps. The process requires root access. Follow:
- How do I properly install a system app given its .apk?
- Installing .apk as system app directly (with root)
You can alternatively, albeit with root access, disable the component
com.android.packageinstaller.UninstallerActivity. (Elixir 2 can do that easily.) That component shows the the dialog to uninstall the app. If you prevent the appearance of that you won't be able to uninstall the app through GUI.
In absence of root access, consider disabling the Package Installer app. It is a system app which handles installation (sideloaded apps) and uninstallation of apps through GUI. It can be disabled from Settings → Apps → (three-dots line → Show System) or (All Apps) → Package Installer → Disable.
One side effect of disabling Package Installer completely or its aforesaid component is that you won't be able to uninstall any app through Settings app either (Play Store is exception). Re-enable Package Installer to uninstall any app from Settings app again.