4

I have an android app that sends some data via FTP. Now, I want to add the possibility of passing that data even via USB if there is no available network.

I was trying to use the solution from the following question but it has no effect. The external device is just the SDcard and not windows desktop.

Is there any way to make something like showing a "synchronization" message when a device is connected and then by pressing a button to pass a file to the Windows folder?

I thought of making a Windows program that was going to launch ADB commands like adb pull when the device is connected. However, is there a way to do it only from Android Application?

srjhnd
  • 189
  • 1
  • 10
NiceToMytyuk
  • 3,644
  • 3
  • 39
  • 100
  • Maybe WiFi Direct? It allows to connect devices wireless (assuming that pc has wifi) without any APN. If you really need to use USB my idea would be to create network between PC (phone would work as a modem) and phone and send files via standard sockets. – Cililing Aug 07 '19 at 14:31

2 Answers2

0

You can use Sockets for this.

I suggest you give this a read.

Then check this for sample code.

Azhar92
  • 923
  • 2
  • 8
  • 17
  • Actually i've yet tought about socket but i can't use that solution as i need to know the PC's IP and the app will be used by common people in lot's of locations and they just can't set every time the PC's IP as that will be hard to them even to find it. – NiceToMytyuk Aug 12 '19 at 06:32
0

I think you can't do this, every app I've seen always uses network (local or not) to transfer files. When you plug your smartphone in USB, the computer sees it as a portable storage Device, but you never see your computer through your smartphone...

It all depends on your "if there is no available network", because (as @Cililing said) you could use the local network in WiFi, even if it doesn't has access to the internet. If you really want USB, then (as you said) adb is your best chance to do that...

Maybe you could call adb from your app ? Is it possible to execute adb commands through my android app? - Stack Overflow (I know it's not the best, because it still requires adb, but maybe it will fit your needs ?)

TBG
  • 154
  • 4
  • 18