![android | Embarcadero RAD Studio Delphi C++Builder Blogs](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/android-1.jpg?resize=1140%2C628&ssl=1)
Android 11 is shipping on most new phones, but Android 12 has rolled out to Pixel devices everywhere. Join this webinar to see what has changed in these latest versions of Android and look at some best practices for Android development with tips for targeting the latest versions of the most popular operating system.
View or download Google Slides
Table of Contents
Desktop, Mobile & Tablet Operating System Market Share Worldwide
![Android012631846 | Embarcadero RAD Studio Delphi C++Builder Blogs android 01 2631846](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/02/Android-01-2631846-1807509.jpg?resize=750%2C364&ssl=1)
https://gs.statcounter.com/os-market-share/desktop-mobile-tablet/worldwide/#monthly-200901-202201
Mobile Manufacturer Market Share Worldwide (Jan 2020 – Jan 2022)
![Android021282266 | Embarcadero RAD Studio Delphi C++Builder Blogs android 02 1282266](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/02/Android-02-1282266-8645432.jpg?resize=750%2C370&ssl=1)
https://gs.statcounter.com/vendor-market-share/mobile/worldwide/#monthly-202001-202202
Mobile Manufacturer Market Share Worldwide (Jan 2022)
![Android035514738 | Embarcadero RAD Studio Delphi C++Builder Blogs android 03 5514738](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/02/Android-03-5514738-7765931.jpg?resize=750%2C574&ssl=1)
https://gs.statcounter.com/vendor-market-share/mobile/worldwide/#monthly-202001-202202
Android vs iOS Market Share Worldwide (Jan 2020 – Jan 2022)
![Android049694559 | Embarcadero RAD Studio Delphi C++Builder Blogs android 04 9694559](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/02/Android-04-9694559-1116182.jpg?resize=750%2C418&ssl=1)
https://gs.statcounter.com/vendor-market-share/mobile/worldwide/#monthly-202001-202202
Mobile Android Version Market Share Worldwide (Jan 2020 – Jan 2022)
![Android053367558 | Embarcadero RAD Studio Delphi C++Builder Blogs android 05 3367558](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/02/Android-05-3367558-2812806.jpg?resize=750%2C376&ssl=1)
https://gs.statcounter.com/android-version-market-share/mobile/worldwide/#monthly-202001-202201
Mobile Android Version – Market Share Worldwide (Jan 2022)
![Android063847722 | Embarcadero RAD Studio Delphi C++Builder Blogs android 06 3847722](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/02/Android-06-3847722-1360725.jpg?w=750&ssl=1)
Android 11 is the current leader (Versions 9 to 11 account for 76.4%)
- Android 12 released Oct 4, 2021
- Android 11 released Sept 8, 2020
- Android 10 released Sept 3, 2019
- Android 9 released Aug 6, 2018
- Android 12 = API 31
- Android 11 = API 30
- Android 10 = API 29
- Android 9 = API 28 (Pie)
https://gs.statcounter.com/android-version-market-share/mobile/worldwide/#monthly-202001-202201
Android Play Security & Performance Requirements
- Each year the targetSdkVersion requirement will advance. Within one year following each Android
- release, new apps and app updates will need to target the updated API level or higher.
- November 2021:
- Target API level 30 (Android 11)
- Publish with the Android App Bundle format.
- Required by Google Play Console
- See API migration guide for other changes: developer.android.com/distribute/best-practices/develop/target-sdk
Android Changes in Delphi 11
![Android141711493 | Embarcadero RAD Studio Delphi C++Builder Blogs android 14 1711493](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/02/Android-14-1711493.png?resize=750%2C322&ssl=1)
*** – link
docwiki.embarcadero.com/RADStudio/Alexandria/en/What%27s_New
Support for Android 12?
![Android076407549 | Embarcadero RAD Studio Delphi C++Builder Blogs android 07 6407549](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/02/Android-07-6407549-3725758.jpg?w=750&ssl=1)
Upgrading Existing Android Projects
● Open an Android project build with an older version.
● Navigate to the Projects dockable window.
● Select Android 32-bit as the active target platform.
● Right-click on the Libraries node.
● Click on Revert System Files to Default.
● Customize with 3rd party libraries, etc.
● Repeat for Android-64.
Updating Your Android Tools
- Delphi optionally installs Android SDK 25.2.5 and updates during installation
- Add ADB to your path:
- C:UsersPublicDocumentsEmbarcaderoStudio22.0CatalogRepositoryAndroidSDK-2525-22.0.42600.6491platform-tools
- Add SDKManager to your path:
- C:UsersPublicDocumentsEmbarcaderoStudio22.0CatalogRepositoryAndroidSDK-2525-22.0.42600.6491toolsbin
- Run:
- adb kill-server
- SDKManager —update
- adb version
- If you get an error “.android/repositories.cfg could not be loaded.”
- Verify you have a .android folder in your user directory
- Create an empty repositories.cfg file
- Latest version (as of Feb 2022)
- Android Debug Bridge version 1.0.41
- Version 32.0.0-8006631
Wireless Debugging
- Added in Android 11 (API 30)
- Enter developer mode on Android (tap “Build Number” seven times)
- Enable wireless debugging
- Developer Options -> Wireless Debugging
- Tap “Pair device with pairing code”
- Check “Always allow on this network,” then press “Allow” when prompted.
- From Windows CMD
- adb start-server
- adb pair [ip]:[port] (from pairing dialog)
- [pairing code]
- adb connect [ip]:[port] (from wireless debugging screen)
- Refresh devices in IDE
Android App Bundle Format
Allows Google Play to use Dynamic Delivery application servicing model to generate optimized APKs for each device.
- Project > Options > Building > Delphi Compiler > Compiling
- Generate Android App Bundle file (arm + arm64)
Upon a successful app bundle generation, the IDE presents a dialog containing the .aab file path.
Note: You can not run or debug an App Bundle. To debug the application you have to use .APK package format
New Android Runtime Permission Model
- Introduced in Android 6.0 (API 23) Marshmallow
- Support library covers earlier Android versions
- New model streamlines auto-update process
- Permissions approval triggered at first usage
- Instead of approving all permissions at install
- Gives end users more control over permissions
- Individual permissions can be allowed or denied per app, and changed later
- Managed through new Android API methods checkSelfPermission() & requestPermissions()
More information developer.android.com/training/permissions/requesting
Old Permissions Approval Dialog
- During install all permissions are accepted
- User is unable to deny individual permissions
- All permissions publicized in the manifest
- If permissions change, then the must be approved before updating
New Permission Approval Dialog
- First time you request the individual permission, the user has the option to Deny or Allow
- If the user denies once, then the user can prevent the app from asking again
- It is important when and how you ask (more on this later)
- All permissions still publicized in the manifest
Users Have Granular Permission Control Now
![Android107920934 | Embarcadero RAD Studio Delphi C++Builder Blogs android 10 7920934](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/02/Android-10-7920934.png?resize=750%2C393&ssl=1)
Dangerous vs. Normal Permissions
- The user isn’t prompted for Normal permissions
- Examples: Internet, Vibrate, Bluetooth, etc.
- The user must approve Dangerous permissions
- Typically these involve privacy or potential cost
- They are grouped into permission groups:
- Calendar, Call_Log, Camera, Contacts, Location, Microphone, Phone, Sensors, SMS, & Storage
- User approves an entire group
- For example both Sending and Receiving SMS
- The developer still must declare and request all permissions from the OS in the manifest.
More information developer.android.com/guide/topics/permissions/overview
How to Ask for Permission – Delphi
![Android095835008 | Embarcadero RAD Studio Delphi C++Builder Blogs android 09 5835008](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/02/Android-09-5835008.png?resize=750%2C328&ssl=1)
More information: docwiki.embarcadero.com/RADStudio/en/Android_Permission_Model
The Permission Service
- System.Permissions contains an instance of TPermissionsService called PermissionsService or access it via the DefaultService property
- IsPermissionGranted: if a permission is currently granted to the app
- RequestPermissions: Request specific permissions and their family
- IsEveryPermissionGranted: if listed permissions are currently granted
- New relevant/related types added to the RTL Android units
- Manifest.permission and Build.VERSION in Androidapi.JNI.Os.pas
- ContextCompat, ActivityCompat, and PermissionChecker in Androidapi.JNI.Support.pas
IsPermissionGranted Method
- Member of System.Permissions.TPermissionsService
- function IsPermissionGranted(const APermission: string): Boolean;
- Find out if a permission is currently granted to the app
- Never assume it is still granted
- If there is no platform permissions service implemented to actually do any checking, then it defaults to responding that all permissions are granted
IsEveryPermissionGranted Method
- docwiki:/RADStudio/Uses_Permissions
- docwiki:Libraries/System.Permissions.TPermissionsService.IsEveryPermissionGranted
- Member of System.Permissions.TPermissionsService
- function IsEveryPermissionGranted(const APermissions: TArray<string>): Boolean;
- Find out if all listed permissions are currently granted
- Never assume it is still granted
- Permission strings found in TJManifest_permission.JavaClass from Androidapi.JNI.Os
- List of permissions and descriptions
RequestPermissions
- Member of System.Permissions.TPermissionsService
- procedure RequestPermissions(
- const APermissions: TArray<string>;
- const AOnRequestPermissionsResult:
- TRequestPermissionsResult[Event|Proc];
- AOnDisplayRationale: TDisplayRationale[Event|Proc] = nil);
- Request one or more permissions
- Any permissions that are not currently granted will be requested.
- Beforehand, a rationale may be displayed to the user when a rationale string has been set for the permission in question requesting a permission again that was previously denied a rationale display routine is passed
- docwiki:Libraries/System.Permissions.TPermissionsService.RequestPermissions
TRequestPermissionsResult[Event|Proc]
- Callback from RequestPermissions
- TRequestPermissionsResult[Event|Proc] =
- procedure(Sender: TObject;
- const APermissions: TArray<string>;
- const AGrantResults: TArray<TPermissionStatus>);
- Callback type for when the system has processed our permission requests
- For each requested permission in APermissions, there is a Boolean in AGrantResults indicating if the permission was granted.
When to Ask for Permissions
![Android115541305 | Embarcadero RAD Studio Delphi C++Builder Blogs android 11 5541305](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/02/Android-11-5541305.png?resize=750%2C335&ssl=1)
When to Ask – Critical Permissions
![Android126122915 | Embarcadero RAD Studio Delphi C++Builder Blogs android 12 6122915](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/02/Android-12-6122915.png?resize=750%2C341&ssl=1)
When to Ask – Secondary Permissions
![Android135454135 | Embarcadero RAD Studio Delphi C++Builder Blogs android 13 5454135](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/02/Android-13-5454135.png?resize=750%2C338&ssl=1)
Other Best Practices
- Use Async version of Methods and Dialogs
- DO NOT block the UI thread!
- Always use HTTPS (everything should be secure)
- Use the new HTTP Client Libraries docwiki.embarcadero.com/RADStudio/en/Using_an_HTTP_Client
- Indy is still available, updated, and supported
- Get to know the Parallel Programming Library
- Get to know System.IOUtils and TPath
- Get to know ADB, logcat & Log.d
More information
- Writing to SD-Card stackoverflow.com/a/57600189/255
- Get Removable SD Card Path
- Androidapi.JNI.Os.pas
- getExternalStorageDirectory
- getExternalStoragePublicDirectory
- getExternalStorageState
- Androidapi.JNI.Os.pas
- Check out “Mobile Permissions Component for Android” in GetIt
Next Steps
- Start a RAD Studio trial embarcadero.com/products/rad-studio/start-for-free
- Get Community Edition embarcadero.com/products/delphi/starter
- Upgrade Today! embarcadero.com/app-development-tools-store/rad-studio
- See special offers embarcadero.com/radoffer
- Subscribe on YouTube youtube.com/c/EmbarcaderoTechnologies
- Follow us on Twitter twitter.com/embarcaderotech
- Like us on Facebook facebook.com/embarcaderotech
- Follow us on LinkedIn linkedin.com/company/embarcadero-technologies
- Read our blog blogs.embarcadero.com
Upgrade to Delphi 11 Today and develop applications on Android 11 & 12 platforms with the use of Android App Builder Software that supports Delphi and C++ environments.
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition
Just a note about getting Android API statistics – you can find the latest Android Platform/API Version Distribution statistics using Android Studio | File Create New Project (Android Phone app for example) then on the first page – click on the “help me choose” under the minimum SDK dropdown and a chart will appear showing what percentage of the different API distributions are.
Hi there Delphi developers, I have just install Delphi 11, I’m having a problem and I wonder if somebody has found a solution.
I have create a “Hello world” app with just one button and y have tested with Android Emulator with differents Emulated devices. Works fine in Android 11 API30 and Android 12 API31, but when I test it in Android 12 API32, the app show the splash screen and get closed after a few seconds.
I have an app in the Play Store and some users with android 12 are reporting this problem, I guess is because they have updated the device to Android 12 API 31. I have been able to test my app in real devices with Android 12 API 30 and works perfect.
It would save my live if somebody could tell me how to solve it.
Thank you.