- Reminder: the target API level ("TargetSdkVersion")
- Applications that request background location permission
- Applications that require access to files
Android 11: Changes in the behavior of applications
After each new version of Android is deployed, Google requires a higher target API level ("TargetSdkVersion") to publish applications on Google Play.
These are the changes that apply to applications:
- Geolocation: Unable to combine ACCESS_FINE_LOCATION and ACCESS_BACKGROUND_LOCATION permission requests into one operation. This implies a change in the code of applications that use background location.
- Access to files: applications in Android 11 can no longer access files created by another application by using their path. This implies a verification of the file handling processes and changes in the code, if necessary.
- Limitations on access to Mac addresses: The NetMACAddress function is no longer available. It always returns an empty string.
Reminder: the target API level ("TargetSdkVersion")
When an Android application is compiled, the generated APK includes a target API level ("TargetSdkVersion") of the Android SDK. With this level of target API, Android determines the features that can be included in the application, and the security rules that must be applied to it.
The target API level ("TargetSdkVersion") assigned to an application can be seen in the APK generation wizard, in the "Configuration" step:
- Click "Advanced configuration",
- In the "Advanced configuration" window, select "Edit manifest",
- Expand the "uses-sdk" node,
- "android:targetSdkVersion" shows the target API level.
Applications that request background location permission
From WINDEV Mobile 26 Update 3, only the location permissions (ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION) will be integrated when generating the application, if necessary.
For applications that require background location access, you need to:
- Manually add the "ACCESS_BACKGROUND_LOCATION" permission in the Android application generation wizard.
- Explicitly request background location permission using PermissionRequest. For example:
INTERNAL PROCÉDURE Callback(p is Permission)
IF p.Granted THEN
// Functions that require background location access can be used
- Follow Google's guidelines for applications that require background location access. For more details, see https://support.google.com/googleplay/android-developer/answer/9799150. If these conditions are not met (especially user information requirements), applications may not be accepted for publication on Google Play.
- The background location permission should only be requested if the location permission has been granted. Otherwise, PermissionRequest will fail.
- If the option chosen by the user for the background location access request is more restrictive than the option chosen for the location access request, the application will be automatically restarted.
- On devices running Android 10 or earlier, if location permission has been granted to the application, the background location permission will be granted without displaying a window.
- The relevant WLanguage functions are as follows:
|BeaconDetectBackground||Notifies the application when the device enters or leaves the transmission range of a set of Beacons.|
|BeaconDetectPrecise||Used to find the Beacons near the device.|
|BTLEListDevice||Returns the list of accessible Bluetooth Low Energy devices.|
|BTListDevice||Returns the list of accessible Bluetooth devices.|
|geoTrackingEnable||Enables the management of location tracking in a WINDEV Mobile application.|
|GPSDetectPosition||Asks to be notified when the device gets close to a given location.|
|GPSFollowMovement||Requests to be notified periodically of the device's current location.|
|GPSGetPosition||Retrieves information about the current device position.|
|GPSInfo||Returns the information about the location provider used by the application for geolocation functions.|
|GPSInitParameter||Initializes the parameters of geolocation WLanguage functions and finds a location provider.|
|GPSLastPosition||Retrieves the information about the last known device position.|
|GPSStatus||Retrieves the activation status of the geolocation provider or asks to be notified when the status changes.|
|GPSStopDetection||Stops the location detection triggered by GPSDetectPosition.|
|MapFollowMovement||Displays the current location of the device in a Map control and updates the location as it moves.|
|MobileNetworkConnectionInfo||Returns information regarding the current connection to data on the mobile network.|
|WiFiDetectAccessPoint||Starts detecting the Wi-Fi access points currently accessible from the device.|
Applications that require access to files
Up to Android 10
, applications can read from and write to files:
When the application is used on a device that runs Android 11
- in the application directories on the internal storage (fCurrentDir, fExeDir, fDataDir)
- almost anywhere in the external storage :
- custom tree structure from the root of the external storage returned by SysDirStorageCard
- in the application directories on the external storage: SysDirExternalStorage with sseAppXXX constants.
- in public directories: Documents, Download, Images, etc. on external storage: SysDirExternalStorage with ssePublicXXX constants.Android applications can access files created by other applications on the external storage without restrictions.
, new restrictions appear:
- applications can no longer read or write files to the external storage outside of:
- in public directories, an application can only access (in read or write mode) the files that it has created.
Remark: if the application is uninstalled and then reinstalled, it will no longer have access to files created by the version previously installed in the public directories of the external storage.
This means applications can no longer access files created by another application by using their path. The end user must select the files that the application can access. It is possible display a file picker using URISelect
function and then handle the file by the URI returned by the function.
However, there is a special permission to override these restrictions: MANAGE_EXTERNAL_STORAGE. To activate it, you must:
- Manually add the MANAGE_EXTERNAL_STORAGE permission in the Android application generation wizard.
- Explicitly request external storage access using PermissionRequest. For example:
INTERNAL PROCEDURE Callback(p is Permission)
IF p.Granted THEN
// Functions that require external storage access can be used
This permission request does not open the standard permission popup, but will open a system window to allow the application to access all files on the external storage without restrictions.
Caution: if the application is to be published on Google Play, the use of this permission must be justified. Only file manager, antivirus or backup manager applications are allowed. In other cases, if this permission is used, the publication is very likely to be refused.
Alternative solution (for existing applications only)
: Add the preserveLegacyExternalStorage
attribute to the application manifest. The process for adding the preserveLegacyExternalStorage
attribute to an application is detailed in FAQ 21 548:
How to allow an existing application to access files on the external storage? (preserveLegacyExternalStorage attribute)
This allows keeping the same access rules as before the API level change, but it will be effective only for existing applications. For new applications or applications that are uninstalled and then reinstalled, this option will be ignored.