“Day 1 of my participation in the First Revision Challenge 2022. For details: First Revision Challenge 2022”
preface
Android location-related permissions include:
ACCESS_COARSE_LOCATION: general location (mainly used for network positioning, obtaining location information based on the base station and Wi-Fi information)
ACCESS_FINE_LOCATION: exact location (mainly used for GPS positioning)
ACCESS_BACKGROUND_LOCATION: background permissions (added in API 29, permissions required for background location access)
Major differences
The major versions involved are Android 6 or later, Android 6 (API level 23) or later, Android 10 (API level 29) or Android 11 (API level 30) or later.
Android under 6
Android 6 has no special requirements for permissions, as long as they are declared in androidmanifest.xml.
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Copy the code
Android 6 (API level 23) or above
In Android 6, restrictions on application permissions are added to dynamically apply for dangerous permissions. The location permissions involved, ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION, both require dynamic requests to be granted.
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) ! = PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) ! = PackageManager.PERMISSION_GRANTED) { String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}; ActivityCompat.requestPermissions(this, permissions, 1);
}
Copy the code
Android 10 (API level 29)
In Android 10 (API level 29), the ACCESS_BACKGROUND_LOCATION background permission is added. The ACCESS_BACKGROUND_LOCATION permission must be declared in the androidmanifest.xml list of the application. The application can return location information only when it is in the background and dynamically applies for location-related permissions. In Android 10, all three permissions can be applied for at the same time. When an application is running on an Android 10 device and requests background access to location information, the system permissions dialog box contains an always-allowed option. If you select this option, the application will have access to location information in the background.
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
Copy the code
Android 11 (API level 30) or later
Android 11 or later does not have the option to always allow permissions in the system dialog box, and you can only enable background permissions on the system Settings page. If the window does not pop up when you apply for the three permissions, the system ignores the permission request and does not grant any of them. For Android 11 or later, you need to apply for ACCESS_COARSE_LOCATIO and ACCESS_FINE_LOCATION and then ACCESS_BACKGROUND_LOCATION to ensure that the foreground and background location access permissions are normal.
conclusion
This is the difference between dynamic application and background permission application after Android 10. In the end, I wish you a happy holiday and auspicious year of the Tiger
Off-topic: after all, it is not until the first snow in Nanjing! Like winter, because it is a romantic season, there is snow ~ family happy Spring Festival is also in this season.