Recent Posts

Site Creator

By

By

By

Implementing Location Permission in Android 5.0 or below

Posted on

Dear Friend

For accessing GPS Location Services GPS is to be turned on. Since turning on GPS impacts device battery’s life so System has given a privilege to user so he or she can turn on or off GPS as required from Setting or Quick Settings.

So if GPS functionality is critical to application we application developers should ask user to Turn on GPS if it not on. So application can use Location Services . You must have seen popular Location based Apps like Uber App or OLA app

 

Reference image

 

pr_location

By the way these apps have made life easy. 🙂

 

Implementation

please have a look at below function

So above code is self explanatory we check the GPS is turned on or off. if it is off we ask user to turn it on. and if it is on we do other cooler stuff.

Note

 
You need to remember doing implementation this way on Android 5.0 or below device provide the GPS permission to application directly if GPS is turned on. Now in Android Marshmallow a new permission model is introduced called Runtime permission which has changed the way how application request location permission from user. For that discussion please have a look at my another blog post.

Happy coding.







Disclaimer: The aforesaid writeup by Relsell Global writer is for the general understanding of the readers. It does not render any professional advice or opinion.

SHARE THIS PAGE!