is it possible to turn location services on via code?
Via Play Services’ SettingsApi
, yes. Otherwise, no, except perhaps on rooted devices or in a custom malware-friendly ROM.
Actually that opens up a dialog box, i don’t want to involve user in it
Then that is not possible.
I have searched for code to do so i have found some and on execution of code it gives some sort of security exceptions
There have been various security flaws in Android that, when exploited, would allow apps to enable GPS silently. AFAIK, all of them are fixed at this point.
if impossible why so?
Privacy.
solved Android how to turn Location services on programmatically?