Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
447 views
in Technique[技术] by (71.8m points)

Android how to turn Location services on programmatically?

I am building an android app to track my device, is it possible to turn location services on via code? I have searched for code to do so I have found some and on execution of code it gives some sort of security exceptions, and some threads here on stack overflow were saying that it is impossible to do so, If possible please provide code, if impossible why so?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...