Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
441 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...