0

I want to use user's location in my android app. But I want the user to allow the app to use the user's location. So I want to have a dialog asking for user's permission to use the location when the user starts the app.

To use the location I know I have to use the <uses-permissions> in the AndroidManifest.xml
e.g. <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION">

So now I want to control this permission programmatically. Can it be done? If Yes please share some pointers.

Thanks, Punit

Gadenkan
  • 1,691
  • 2
  • 17
  • 29
  • I think you have to try these links http://developer.android.com/guide/topics/location/obtaining-user-location.html and http://stackoverflow.com/questions/4015094/android-enable-and-disable-gps – Newts Dec 01 '11 at 08:00

3 Answers3

0

Yes it can be done only if phone is rooted though! There are apps on Google Play Store to do just that. And here is an open source project that does it to: https://groups.google.com/forum/?fromgroups#!topic/android-developers/aouN769ewOU

3c71
  • 4,313
  • 31
  • 43
0

So now I want to control this permission programmatically. Can it be done?

No, sorry. You have to ask for that permission in the manifest, and the user has to grant that permission at install time.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
0

You can't do that.

But what you can do is create a boolean variable in SharedPreferences and then check that in your service / activity.

SERPRO
  • 10,015
  • 8
  • 46
  • 63