Via Cà Matta 2 - Peschiera Borromeo (MI)
+39 02 00704272
info@synaptica.info

Retrive the Imei (device identification) from your Android Device with Delphi XE5

Digital Innovation Partner

Retrive the Imei (device identification) from your Android Device with Delphi XE5

The IMEI code is an unique number like the MAC Adrress for the lan on mobile devices…

so in this example i have only putted a TButton on the form and wrote this piece of code that i found on the net:

uses System.IOUtils,IdGlobalProtocols {$IFDEF ANDROID}
,FMX.Helpers.Android, Androidapi.JNI.GraphicsContentViewText,
Androidapi.JNI.Net, Androidapi.JNI.JavaTypes, idUri,Androidapi.IOUtils
{$ENDIF ANDROID}
{$IFDEF MSWINDOWS }, WinAPI.ShellApi, WinAPI.Windows {$ENDIF}
{$IFDEF ANDROID} ,Androidapi.JNI.Telephony, Androidapi.JNI.Provider,
Androidapi.JNIBridge,
Androidapi.Jni,
Androidapi.JNI.Dalvik {$ENDIF ANDROID};

procedure TfrmMain.Button1Click(Sender: TObject);
var
{$IFDEF ANDROID}
obj: JObject;
tm: JTelephonyManager;
{$ENDIF}
identifier: String;

begin
{$IFDEF ANDROID}
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));
{$ENDIF ANDROID}
ShowMessage(identifier);

end;

Lascia un commento