Get access to over 100 FireMonkey cross platform samples for Android, IOS, OSX, Windows, and Linux!

AndroidAppmethodCode SnippetDelphiFiremonkey

Read The IMEI Device ID With Delphi XE5 Firemonkey On Android

Delphi XE5 Firemonkey Android IMEIHere is a code snippet which gets the Android device IMEI for you using the Android JNI. The IMEI (International Mobile Equipment Identity) is a unique device ID separate from your SIM card. Accessing the IMEI also requires that your app has the READ_PHONE_STATE permission to be able to access it. I’m not sure who wrote the original example code but on the Embarcadero forum Remy Lebeau posted this code snippet in October of 2013. Here is the full permission line for the Android manifest:

And here is the code snippet:
uses
Androidapi.JNI.Telephony, Androidapi.JNI.Provider ,
Androidapi.JNIBridge, Androidapi.JNI.GraphicsContentViewText ,
Androidapi.JNI.JavaTypes,FMX.Helpers.Android;

var
obj: JObject;
tm: JTelephonyManager;
identifier: String;
begin
obj := SharedActivityContext.getSystemService(TJContext.JavaClass.TELEPHONY_SERVICE);
if obj <> nil then
begin
tm := TJTelephonyManager.Wrap( (obj as ILocalObject).GetObjectID );
if tm <> nil then
identifier := JStringToString(tm.getDeviceId);
end;
if identifier = '' then
identifier := JStringToString(TJSettings_Secure.JavaClass.getString(SharedActivity.getContentResolver,
TJSettings_Secure.JavaClass.ANDROID_ID));

end;
There are also two other blog posts with slightly different code for retrieving the IMEI on Android with Delphi XE5 Firemonkey here and here.

Head over to the Embercadero forum to read the full thread about getting the IMEI on Android.

Have Delphi Firemonkey questions? Ask and get answers on StackOverflow.

Related posts
ComponentDelphiFiremonkeyIOSLinuxOSXWindows

Build Modern ChatGPT-Style AI Interfaces In FireMonkey

ComponentDelphiFiremonkeyUtilityWindows

Bring OpenClaw-Style AI Agents To Delphi And Object Pascal

C++BuilderDelphiFiremonkeyIDEUtility

Build And Design Delphi FireMonkey Apps With AI Inside RAD Studio

DelphiUtilityWindows

Give AI Agents A Searchable Map Of Firemonkey APIs And Examples

Sign up for our Newsletter and
stay informed
[mailpoet_form id="1"]

6 Comments

Leave a Reply