Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
News

Developing for Android 11 & 12 with Delphi 11 Alexandria

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

Desktop, Mobile & Tablet Operating System Market Share Worldwide

android-01-2631846

https://gs.statcounter.com/os-market-share/desktop-mobile-tablet/worldwide/#monthly-200901-202201

Mobile Manufacturer Market Share Worldwide (Jan 2020 – Jan 2022)

android-02-1282266

https://gs.statcounter.com/vendor-market-share/mobile/worldwide/#monthly-202001-202202

Mobile Manufacturer Market Share Worldwide (Jan 2022)

android-03-5514738

https://gs.statcounter.com/vendor-market-share/mobile/worldwide/#monthly-202001-202202

Android vs iOS Market Share Worldwide (Jan 2020 – Jan 2022)

android-04-9694559

https://gs.statcounter.com/vendor-market-share/mobile/worldwide/#monthly-202001-202202

Mobile Android Version Market Share Worldwide (Jan 2020 – Jan 2022)

android-05-3367558

https://gs.statcounter.com/android-version-market-share/mobile/worldwide/#monthly-202001-202201

Mobile Android Version – Market Share Worldwide (Jan 2022)

android-06-3847722

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

android-14-1711493

*** – link

docwiki.embarcadero.com/RADStudio/Alexandria/en/What%27s_New

Support for Android 12?

android-07-6407549

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

docwiki.embarcadero.com/RADStudio/en/Submitting_Your_Android_App_to_Google_Play#Android_App_Bundle_Support

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

android-10-7920934

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

android-09-5835008

More information: docwiki.embarcadero.com/RADStudio/en/Android_Permission_Model

The Permission Service

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

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]

When to Ask for Permissions

android-11-5541305

When to Ask – Critical Permissions

android-12-6122915

When to Ask – Secondary Permissions

android-13-5454135

Other Best Practices

More information

Next Steps

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.


What's Coming in Delphi, C++Builder, and RAD Studio 11.2 Alexandria

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

About author

Chief Developer Advocate for Embarcadero Technologies.

2 Comments

Leave a Reply to Antonio Piñero Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES