简体   繁体   中英

Transfer Data between two android phones using Usb host Api

I am trying to send some data from one Android phone(Nexus 5), which is working as Usb Host, to Android tablet(Samsung Tab 4).

I am using bulkTransfer() method to transfer data from Nexus 5, which is returning the length of data that has been transferred successfully.

My question is How can I verify on the other end (at Samsung Tab), that yes I am getting the data that I had transferred from Nexus 5 ?

Here is some code snippet of transferring data

   usbDeviceConnection = manager.openDevice(device);
   boolean flag =  usbDeviceConnection.claimInterface(usbInterface, true);
   String text = textValue.getText().toString();
   byteArray = text.getBytes();

   //  data transfer
   int a = usbDeviceConnection.bulkTransfer(endpointOut, byteArray, byteArray.length, 0);

   if(a>0){
              textInfo.setText("Data has been transferred successfully..."
                             +"\n"+"Length of data: "+a
   );

Please help me to do this task...!

After digging the Usb Host API I have found something that the other end (Samsung Tab) can work in Accessory mode and we can access the Usb Host (Nexus 5) by using the "android.hardware.usb.accessory" library.

Since the android phone who can support the Usb Host feature for example like Nexus 5 can access the device connected to it using "android.hardware.usb.host" library.

The other one for example Samsung Tab(It must support AOAP Protocol ) who does not support the Usb Host feature will access the device connected to it using "android.hardware.usb.accessory" library.

To understand The Usb Host feature you can open the link http://developer.android.com/guide/topics/connectivity/usb/host.html

To understand The Usb Accessory feature you can open the link http://developer.android.com/guide/topics/connectivity/usb/accessory.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM