Possible Duplicate:
Determine if running on a rooted device
How do you determine (programmatically) if an Android device is: rooted Running a cracked copy of your software or rom.
I have some sensitive information in my database, and I would like to encrypt it when the phone is rooted aka the user has access to the database. How do I detect that?
Rooting detection is a cat and mouse game and it is hard to make rooting detection that will work on all devices for all cases.
See Android Root Beer https://github.com/scottyab/rootbeer for advanced root detection which also uses JNI and native CPP code compiled into .so native library.
If you need some simple and basic rooting detection check the code below:
Probably not always correct. Tested on ~10 devices in 2014.