How to Detect a Rooted Android Device Programmatically

Security is a key part of development, and when it comes to Android applications, it becomes extremely critical.