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; |
Platform : Delphi XE5 Update 2 Only a function to open file in Windows,Android, Ios…. Windows –> shellExecute Android –> sending an intent to SO Ios –> using NSUrl
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
uses ... IdGlobalProtocols,{$IFDEF MSWINDOWS}, WinFolderSelectUtils {$ENDIF} {$IFDEF MSWINDOWS }, WinAPI.ShellApi, WinAPI.Windows {$ENDIF} {$IFDEF ANDROID} ,FMX.Helpers.Android, Androidapi.JNI.GraphicsContentViewText, Androidapi.JNI.Net, Androidapi.JNI.JavaTypes, idUri,Androidapi.IOUtils {$ENDIF ANDROID} {$IFDEF IOS} ,iOSapi.Foundation, FMX.Helpers.iOS {$ENDIF IOS}; function OpenURLorFile(URL: string; const DisplayError: Boolean = False): Boolean; {$IFDEF MSWINDOWS} begin ShellExecute(0, 'OPEN', PChar(URL), '', '', SW_SHOWNORMAL); end; {$ELSE} {$IFDEF ANDROID} var Intent: JIntent; idMimeTable: TIdMimeTable; begin // There may be an issue with the geo: prefix and URLEncode. // will need to research if URl.toLower.StartsWith('http://') then Begin Intent := TJIntent.JavaClass.init(TJIntent.JavaClass.ACTION_VIEW, TJnet_Uri.JavaClass.parse(StringToJString(TIdURI.URLEncode(URL)))); End Else Begin try idMimeTable := TidMimeTable.Create; Intent := TJIntent.Create; Intent.setAction(TJIntent.JavaClass.ACTION_VIEW); if not url.ToLower.StartsWith('file://') then url := 'file://' + url; Intent.setDataAndType(StrToJURI(Url), StringToJString(idMimeTable.GetFileMIMEType(Url))); Finally try idMimeTable.Free; except end; End; End; try SharedActivity.startActivity(Intent); exit(true); except on e: Exception do begin if DisplayError then ShowMessage('Error: ' + e.Message); exit(false); end; end; end; {$ELSE} {$IFDEF IOS} var NSU: NSUrl; begin // iOS doesn't like spaces, so URL encode is important. NSU := StrToNSUrl(TIdURI.URLEncode(URL)); if SharedApplication.canOpenURL(NSU) then exit(SharedApplication.openUrl(NSU)) else begin if DisplayError then ShowMessage('Error: Opening "' + URL + '" not supported.'); exit(false); end; end; {$ELSE} begin raise Exception.Create('Not supported!'); end; {$ENDIF IOS} {$ENDIF ANDROID} {$ENDIF WINDOWS} |
to generate uid or GUID with delphi:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
program Guid; {$APPTYPE CONSOLE} uses SysUtils; var Uid: TGuid; Result: HResult; begin Result := CreateGuid(Uid); if Result = S_OK then WriteLn(GuidToString(Uid)); end. |
Come tutti sappiamo, creare un webServer con Delphi è semplicissimo, cosa meno banale è invece decodificare una post che che contiene un multipart/form-data. Quando una paginetta http esegue una http submit da un form in metodo post, magari con un file in upload il browser genera uno stream codificato in UTF8 in cui ci sono…
Leggi tutto
Con FastReport 4 esportare un report in PDF su stream è semplicissimo, bastano 5 minuti … peccato che non è spiegato nella documentazione, quindi per capire come funzionava l’arcano ci ho perso due ore… di seguito una porzione di codice come esempio: procedure TForm1.Button3Click(Sender: TObject); var st : TMemoryStream; begin st := TMemoryStream.Create; Try TBlobField(csReports.FieldByName(‘Report’)).SaveToStream(st);…
Leggi tutto