Bonjour à tous,

Avec Delphi 10 Seattle, c'est ma première application Android.

Mon appli./Android doit prendre des photos et les enregistrer dans un dossier partagé (Windows), pour certaines fonction de cette appli., sur la base d'un exemple existant sur internet, j'ai utilisé le protocole "smb".

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
 
     If (IpServer = '') Or (AppDir = '') Or (UserName = '') Then
     Begin
          FParam.Show;
          Exit;
     End;
     EConnexion := False;
     Try
        Toast ('Connexion au serveur ...');
        networkshare := TJSmbFile.JavaClass.init(StringToJString(RootText+Uppercase(IpServer)+'/'),auth);
        Sleep (555);
        If (networkshare.exists) And (Assigned(networkshare)) Then
        Begin
             Try
                Toast ('Authentification ...');
                auth:=TJNtlmPasswordAuthentication.JavaClass.init(StringToJString(''),StringToJString(UserName),StringToJString(PassWord));
                networkshare := TJSmbFile.JavaClass.init(networkshare.toString,auth);
                Sleep (555);
                If networkshare.isDirectory Then
                Begin
                     Try
                        Toast ('Connexion au dossier GNC ...');
                        networkshare := TJSmbFile.JavaClass.init(StringToJString(Uppercase('smb://'+ IpServer +'/'+AppDir + '/Data/')),auth);
                        Sleep (555);
                        If networkshare.isDirectory Then
                           EConnexion := True;
                     Except
                        On E: Exception Do
                          // Toast ('Erreur de connexion au dossier GNC ...'); //''authentification');
                        EConnexion := False;
                     End;
                End;
             Except
                On E: Exception Do
                   EConnexion := False;
             End;
        End;
     Except
        On E: Exception Do
           EConnexion := False;
     End;
     If Not EConnexion Then
        Toast ('Erreur de connexion au serveur ...');
L’authentification de l'Android fonctionne correctement et j'arrive à copier des fichiers de Windows vers l'Android avec cette procédure :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
 
Function TFMenu.Find_File (NFile : String) : Boolean;
Var
     ListF  : TJavaObjectArray<JSmbFile>;
     DPath  : String;
     N      : Integer;
begin
     If NFile <> 'PRESTAT-EC.TXT' Then
        networkshare := TJSmbFile.JavaClass.init(StringToJString(TPath.GetSharedDownloadsPath + '/' + NDossier),auth);
     Result := False;
     ListF  := Networkshare.listFiles;
     EConnexion   := False;
     For N := 1 To Pred (ListF.Length) Do
     begin
          If NFile <> 'PRESTAT-EC.TXT' Then
             Toast ('Fichier = ' + JStringToString (ListF.Items [N].getName));
         If Pos (NFile, UpperCase (JStringToString (ListF.Items [N].getName))) > 0 Then
         Begin
              LocFile := ListF.Items [N];
              Result  := True;
         End;
     end;
End;
 
procedure TFMenu.CopyFile(source : JSmbFile; dest : String);
const
  bufferSize = 4096*2;
var
  noOfBytes          : Integer;
  b                  : TJavaArray<Byte>;
  localinfile        : JInputStream;
  localfileoutstream : JFileOutputStream;
begin
  // Copy a file from share to local the Android way
  try
    localinfile := source.getInputStream;
    localfileoutstream := TJFileOutputStream.JavaClass.init(StringToJString(dest));
    b := TJavaArray<Byte>.Create(bufferSize);
    noOfBytes := localinfile.read(b);
    while (noOfBytes > 0) do
    begin
      localfileoutstream.write(b, 0, noOfBytes);
      noOfBytes := localinfile.read(b);
    end;
    localfileoutstream.close;
    localinfile.close;
  except
    on E: Exception do
       Toast ('Copy file: '+E.ClassName + ': ' + E.Message);
  end;
end;
Mon problème est l’initialisation d'un fichier (JSmbFile) pour copier le de l'Android vers Windows !!!

Pourriez vous m'aider svp ?

Merci à tous.