Enable/Diasble Using “user location” programmatically in android
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.
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.
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.
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