0

How do I request permission for my location (api 23>) when I want to access the location inside a service?

I have a service running every minute fetching data from a URL. In this service I want to pass my location in the URL but I have issues requesting the permission for my location (since you cant do that inside a service). How can I request permission in my MainActivity?

EDIT: I think my problem is requesting permissions inside a service. My service is started with alarmManager (setRepeating), and in this service I want to access my real time location. When I try to request permission there it does not work. Can I request permissions elsewhere?

Abhishek Bedi
  • 5,205
  • 2
  • 36
  • 62
Stu2dent
  • 11
  • 1
  • Possible duplicate of [Request Location Permissions from a service Android M](http://stackoverflow.com/questions/33867088/request-location-permissions-from-a-service-android-m) – Mike M. Aug 24 '16 at 09:22

1 Answers1

0

Update: If the app starts for the first time, you can ask the user for permission (from your Activity) - user can grant or deny the permission.

If user has denied the permission you should stop/don't start your service and inform the user that, without this permission, your app doesn't work.

See Requesting Permissions at Run Time.

Thomas S.E.
  • 1,528
  • 16
  • 28
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/13443668) – n1ckolas Aug 24 '16 at 09:41
  • That's true, but 30 seconds of searching would have answered his question. – Thomas S.E. Aug 24 '16 at 10:41