mardi 8 avril 2014

Hôte Android : connexion avec un dispositif d'USB de stockage de masse - Stack Overflow


I am currently trying to develop an application who access xml files on an usb device. I have read the Google Documentation about Android USB Host. Now i can detect my USB Device, discover its specifications (like PID/VID), but i can't access on the files of the USB device :(


Here is my code of the activity looking for devices :


public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_visu);


affichage = (TextView) findViewById(R.id.afficher);
context = VisuActivity.this.getApplicationContext();
UsbManager manager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
HashMap<String, UsbDevice> deviceList = manager.getDeviceList();

Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();

if(deviceList.size()==1){
while(deviceIterator.hasNext()){
device = deviceIterator.next();

}

UsbInterface mUsbInterface = device.getInterface(0);
UsbEndpoint endpoint = mUsbInterface.getEndpoint(0);

UsbDeviceConnection connection = manager.openDevice(device);

}
}
/* What To Do Now ???? */

I have tried to find some example on the internet, but I am lost now ! :(


Anyone knows how to do for read (and eventually write) a file on a USB device ? I have heard that there is a Mass Storage protocol to follow, but i don't find or understand it !



I am currently trying to develop an application who access xml files on an usb device. I have read the Google Documentation about Android USB Host. Now i can detect my USB Device, discover its specifications (like PID/VID), but i can't access on the files of the USB device :(


Here is my code of the activity looking for devices :


public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_visu);


affichage = (TextView) findViewById(R.id.afficher);
context = VisuActivity.this.getApplicationContext();
UsbManager manager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
HashMap<String, UsbDevice> deviceList = manager.getDeviceList();

Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();

if(deviceList.size()==1){
while(deviceIterator.hasNext()){
device = deviceIterator.next();

}

UsbInterface mUsbInterface = device.getInterface(0);
UsbEndpoint endpoint = mUsbInterface.getEndpoint(0);

UsbDeviceConnection connection = manager.openDevice(device);

}
}
/* What To Do Now ???? */

I have tried to find some example on the internet, but I am lost now ! :(


Anyone knows how to do for read (and eventually write) a file on a USB device ? I have heard that there is a Mass Storage protocol to follow, but i don't find or understand it !


0 commentaires:

Enregistrer un commentaire