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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
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; |