简体   繁体   中英

How to get permissions on runtime for older API versions?

So I've been trying to get started on a simple GPS application but at some point I'm required to ask for user permission on locationManager methods

if (isNetworkEnabled) {
                    locationManager.requestLocationUpdates(
                            locationManager.NETWORK_PROVIDER,
                            MIN_TIME_BW_UPDATES,
                            MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                if (locationManager != null) {
                    location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                    if (location != null) {
                        Latitude = location.getLatitude();
                        Longitude = location.getLongitude();
                    } //location
                } //locationManager
            } //isNetworkEnabled

I understand that there's a simple way to do it for API 23, but I'd like to target Android 4.0.

I've seen a documentation about it ( https://developer.android.com/training/permissions/requesting.html ) but I just don't quite understand how to apply it to my code. I know I'm supposed to use ActivityCompact and ContextCompact but I'm just not sure on how. Please help!

As you pointed out, Android API >= 23 added the new runtime permissions .

For older API the user is promped to accept them all on installation

like in the image below

在此处输入图片说明

You just need to add them in the manifest and nothing else :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM