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 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOS

Delphi XE5 Firemonkey Android IMEI | Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOSHere 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:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
And here is the code snippet:
Androidapi.JNI.Telephony, Androidapi.JNI.Provider ,
Androidapi.JNIBridge, Androidapi.JNI.GraphicsContentViewText ,

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

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

Unleashing Creativity With Song Writer AI: A Deep Dive


How To Build Stable Diffusion Text To Image Prompts


FireMonkey 10.4.2 Features Updated iOS 14, Android 11, And macOS 11 Support Plus Hundreds Of Fixes


Ryzen 9 5950x: One Billion Lines Of Delphi Code Compiled In ~5 Minutes On 16 Cores

Sign up for our Newsletter and
stay informed


Leave a Reply