Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys;
i am developing a project with android and c#. I need data transfer from android app to c# app use usb cable. i search on internet result; generally server clint on tcp/ip or web services use. But i want use usb cable. How can i do data transfer from android to c#.
Posted
Updated 25-Sep-15 11:31am
v3
Comments
Dushantha12 26-Jun-18 5:54am    
Hi, Did you complete this? If yes please post a sample code of C# application. Thank you.

I haven't heard of anything like that in months. Of course you can share the data using USB and you can also determine when a socket is connected to the USB port in C#. For example like this Windows Runtime API for "developing Windows applications for USB[^]". You will get the resources required to program an application that connects to USB ports and communicates (like accessing data) from that document that I have shared right now.

But on the Android side there have not been anything that you can use, apart from that USB debugging thing. If you are still interested in doing so, I suggest you learn more about USB debugging[^] and how it works etc. USB debugging would allow you to get system-level clearance from a PC to perform different actions on Android devices that only system has permissions to.

Sending data from an Android device to a C# based application can have many other solutions if you simply ignore the USB term. I can help you count a few:

1. Creating a USB listener
- Connect your Android and then use the USB port to communicate to it as a USB device, not as Android client.
2. Create a TCP server and allow Android to communicate to it as a TCP client.
3. Create a web service and use it.
- Can be complicated.
4. Create an ASP.NET Web API and use it from the browser in Android device.
5. Use Bluetooth or other technologies for transmitting the data.

These methods can be used if only you can skip the USB term, because USB can share the contents from the device to device, but application to application data sharing is not something that I have heard until now. :-) I would love to know of such a mechanism, if exists. But would be a tough!
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 25-Sep-15 20:56pm    
Fair enough, a 5.
At the same time, my colleague recently discovered the library usblib and got great results. Please see Solution 2.
—SA
Afzaal Ahmad Zeeshan 26-Sep-15 4:18am    
Thank you, Sergey.
[no name] 26-Sep-15 8:09am    
Thank you Afzaal Ahmet Zeeshan
Afzaal Ahmad Zeeshan 26-Sep-15 8:46am    
You are welcome.
mo7amd89 5-Jan-22 5:17am    
Did you find the solution ?
I would suggest using usblib: http://www.libusb.org[^].

I personally did not use it yet, but my colleague recently learned how to use it and got amazingly good and useful results. It can be used for many OS.

For Android, see also:
https://github.com/libusb[^],
https://github.com/libusb/libusb/tree/master/android[^].

—SA
 
Share this answer
 
v2
Comments
Afzaal Ahmad Zeeshan 26-Sep-15 4:18am    
5ed. Good one, I would give it a try to see if I can write a different answer in future. :-) Thank you!
Sergey Alexandrovich Kryukov 26-Sep-15 5:40am    
Thank you, Afzaal.
—SA
[no name] 26-Sep-15 8:10am    
Thanks Sergey
Sergey Alexandrovich Kryukov 26-Sep-15 20:43pm    
You are welcome.
Will you accept this answer formally as well?
—SA
mo7amd89 5-Jan-22 5:16am    
Did you find the solution ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900