Site icon Embarcadero RAD Studio, Delphi, & C++Builder Blogs

Efficiently Manage KeyguardManager API in your Delphi FireMonkey Android Projects

When you begin an enterprise-level project, you must integrate authentication options into your projects. At that point, you can use Android Built-in APIs, such as the KeyguardManager API, to lock and unlock the keyguard in your Delphi or C++ Builder FireMonkey Android application.

To handle this API from your FireMonkey project, we can use the WINSOFT Authentication for Android library. This library is available for Delphi/C++ Builder 10 – 10.4 and uses the Android KeyguardManager API. In this library, we have the TAuthentication class, which is required to handle credential confirmation. This is a commercial library with a trial version that includes all features for evaluation purposes only. If you want to distribute the Authentication for Android library as part of your Android application, you must register a license.

This is the class structure here:

Let’s see how we can implement this class in our real project. The first step is to install this library into our IDE. You can follow the tutorial here to install the library correctly.

The second step is adding the unit name into the uses section.

Add the aAuthentication unit into the uses section.

And now we should declare 2 procedures, one for OnSuccess event and one for OnError event for triggering the events. Moreover, we need an instance of a TAuthentication class, so here I will declare them in the scope of the private declaration.

Result:

[crayon-672a45583e62c212503307/]

Now let’s see our UI for this project.

As you can see this is simple, we have a button for confirming credentials, a memo for showing messages, and a label which is not visible because, in this project, the label shows a message when you have a valid confirmation.

The next is implementing OnSuccess and OnError events.

[crayon-672a45583e632800108793/]

The next step is to create the OnCreate event on TForm and initialize the Authentication instance, setting OnError & OnSuccess notify events and also check if the device is secured or not.

[crayon-672a45583e635414327518/]

With the DeviceSecured property, we can get whether the device is secured with a PIN, password, pattern, or biometrics.

Everything looks good so now we can call the ConfirmCredentials procedure on button click event.

[crayon-672a45583e636487038019/]

The ConfirmCredentials procedure gets an intent to prompt the user to confirm credentials (pin, pattern, password,  or biometrics if enrolled) for the current user of the device.

That is all it takes to implement KeyguardManager API in your FireMonkey Android project. I would recommend that you watch the demo action video below to see the result easily.

Do you want to manage your KeyguardManager API on your android projects with the use of IDE Software? You can get Authentication for Android and over 100 other fantastic WinSoft components with our Enterprise Component Pack. For a limited time, when you purchase RAD Studio Enterprise or Architect Edition at special Upgrade Pricing, you will also get this package of third-party software worth over $13,000, including the full WinSoft Component Library, at NO EXTRA COST! Step up to RAD Studio 10.4 today!

Exit mobile version