Recent

Author Topic: Access to windows folder  (Read 1918 times)

magleft

  • Full Member
  • ***
  • Posts: 125
Access to windows folder
« on: April 22, 2023, 05:24:55 pm »
In Windows I have created a shared folder with read + write permissions, e.g.
//DESKTOP-9ABC8H5/AgrosNet
I would like to access the folder via network share from within android.
I have read the AppShareFileDemo1 and AppPublicFoldersAccessDemo1 examples but I could not find a solution.
I have no knowledge about handling the internet, I can't make the relevant code.
Could someone help me, even for a fee?
windows 10 64

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Access to windows folder
« Reply #1 on: April 22, 2023, 07:07:01 pm »
Normally it is enough to add '\\?\' (without quotes) infront of a UNC path to access its content.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

magleft

  • Full Member
  • ***
  • Posts: 125
Re: Access to windows folder
« Reply #2 on: April 23, 2023, 12:09:50 pm »
First of all I would like to know how I would like the android device to connect to the windows shared folder via wifi.
I built the following application, but it can't find the file 'ApkAgros.db' located in the windows shared folder.
What am I doing wrong;


Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.Button1Click(Sender: TObject);
  2. var
  3.   apath:String;
  4. begin
  5.   apath := '\\?\\\DESKTOP-9ABC8H5\AgrosNet\ApkAgros.db' ;
  6.   if FileExists(apath) then
  7.      showmessage('File Exist')
  8.   else
  9.       Showmessage('Not Exist');
  10. end;
  11.  
  12.  
  13. procedure TAndroidModule1.AndroidModule1JNIPrompt(Sender: TObject);
  14. var
  15.   manifestPermissions: array of string;
  16. begin
  17.   if IsRuntimePermissionNeed() then   // that is, target API >= 23  - Android 6
  18.   begin
  19.      SetLength(manifestPermissions, 1);
  20.      //hint: if you  get "write" permission then you have "read", too!
  21.      //from AndroodManifest.xml
  22.      manifestPermissions[0]:= 'android.permission.WRITE_EXTERNAL_STORAGE';
  23.      // location
  24.      Self.RequestRuntimePermission(manifestPermissions, 701);
  25.      //camera
  26.      Self.RequestRuntimePermission(manifestPermissions, 802);
  27.      //upload
  28.      Self.RequestRuntimePermission(['android.permission.READ_EXTERNAL_STORAGE'], 3027);//android.permission.WRITE_EXTERNAL_STORAGE
  29.      SetLength(manifestPermissions, 0);
  30.      SetLength(manifestPermissions, 3);
  31.      manifestPermissions[0]:= 'android.permission.RECEIVE_SMS';  //from AndroodManifest.xml
  32.      manifestPermissions[1]:= 'android.permission.SEND_SMS'; //from AndroodManifest.xml
  33.      manifestPermissions[2]:= 'android.permission.READ_PHONE_STATE';
  34.      Self.RequestRuntimePermission(manifestPermissions, 2001);
  35.  
  36.      SetLength(manifestPermissions, 2);
  37.  
  38.      manifestPermissions[0]:= 'android.permission.CAMERA';  //from AndroodManifest.xml
  39.      manifestPermissions[1]:= 'android.permission.WRITE_EXTERNAL_STORAGE'; //from AndroodManifest.xml
  40.  
  41.      Self.RequestRuntimePermission(manifestPermissions, 1101);
  42.  
  43.      SetLength(manifestPermissions, 1);
  44.      Self.RequestRuntimePermission(manifestPermissions, 1198);
  45.  
  46.      SetLength(manifestPermissions, 0);
  47.   end;
  48.  
  49. end;
  50.  
  51.  
windows 10 64

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Access to windows folder
« Reply #3 on: April 23, 2023, 04:15:23 pm »
Now I understand better, simplest solution would be to put up on windows machine a Tcp/Ip kind of server (http or ftp probably) and access it easy over that protocol.
Using the windows share will also need to set up a network share, when that is done you need to use a SMB connection from your application to access that share in your Android device.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

magleft

  • Full Member
  • ***
  • Posts: 125
Re: Access to windows folder
« Reply #4 on: April 24, 2023, 05:55:33 pm »
If I understood correctly, the transfer will be done through a server. I'd rather it not be required or virtual as that means extra cost.
I have seen apps on android that can recognize windows shared folder.
I don't know if it is possible through laz4android.
windows 10 64

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Access to windows folder
« Reply #5 on: April 24, 2023, 10:18:30 pm »
Welcome to the world of networking  :P
I do not believe your saying that over Wi-Fi some app is able to get a Windows shared folder. Sound impossible to me but hey, I am here to learn new things aswell.
To me are only 2 options possible that not require a server setup, that is direct USB connection or LAN.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

magleft

  • Full Member
  • ***
  • Posts: 125
Re: Access to windows folder
« Reply #6 on: April 29, 2023, 07:22:05 pm »
I think there are several applications. You can see for example the Cx file explorer app from the play store.
So it definitely does. The question is how?
windows 10 64

TRon

  • Hero Member
  • *****
  • Posts: 4304
Re: Access to windows folder
« Reply #7 on: April 30, 2023, 02:05:53 am »
I think there are several applications. You can see for example the Cx file explorer app from the play store.
So it definitely does. The question is how?
Answered by KodeZwerg

Now I understand better, simplest solution would be to put up on windows machine a Tcp/Ip kind of server (http or ftp probably) and access it easy over that protocol.
Using the windows share will also need to set up a network share, when that is done you need to use a SMB connection from your application to access that share in your Android device.

See for example here for how to setup.

You application thus has to use the SMB protocol to discover the share(s) and to transfer data around. Note that SMB is also named SaMBa (it can help you in your search). I doubt that there is a ready to go example for Free Pascal/lamw so you best bet would be so look for example code written with the native android toolkit.

edit: jcifs and small example and this one for some basics.
« Last Edit: April 30, 2023, 02:25:17 am by TRon »
Today is tomorrow's yesterday.

magleft

  • Full Member
  • ***
  • Posts: 125
Re: Access to windows folder
« Reply #8 on: May 01, 2023, 06:52:09 am »
Thanks for the help. I will try to find a solution for the smb protocol.
I found some help in the forum [url] https://forum.lazarus.freepascal.org/index.php?topic=39149.0 [url]
But apparently Android does not support the TProcess class.
windows 10 64

TRon

  • Hero Member
  • *****
  • Posts: 4304
Re: Access to windows folder
« Reply #9 on: May 01, 2023, 02:03:15 pm »
Thanks for the help. I will try to find a solution for the smb protocol.
There is not a real solution but I lack android/lamw knowledge to know how to describe the path that needs to be taken. afaik there are 2 options:
1) install the jcifs library on your andoriod box, write a jni wrapper for it in Pascal
2) re-implement jcifs in fpc/jni and use that

And perhaps I got that even wrong.

Quote
I found some help in the forum [url] https://forum.lazarus.freepascal.org/index.php?topic=39149.0 [url]
But apparently Android does not support the TProcess class.
afaict the use of "net use" is a Windows only feature meaning that it will not work on/for Android.
Today is tomorrow's yesterday.

 

TinyPortal © 2005-2018