fork from code.google.com/p/jmtp
Add Some Feture:
1.Send Custom MTP Command
example:
@Test
public void testGetNumObjects() throws COMException {
MTPDataset request = new MTPDataset();
request.code = 0x1006;//Operation Code
request.params = new int[]{0xFFFFFFFF, 0, 0x00000000}; //Params
MTPDataset response = MTPHelper.getInstance().sendCMDWithoutDataPhase(device, request);
long responseCode = response.code;
int[] responseParams = response.params;
}
example:
@Test
public void testSetDevicePropValue() throws COMException {
MTPDataset request = new MTPDataset();
request.code = 0x1016;
request.params = new int[]{0xD402};
Buffer buffer = new Buffer();
buffer.writeByte(0x5);
buffer.writeShortLe('X');
buffer.writeShortLe('B');
buffer.writeShortLe('O');
buffer.writeShortLe('X');
buffer.writeShortLe(0);
request.data = buffer.readByteArray(); //Friendly Name MTP Protocol String
MTPDataset response = MTPHelper.getInstance().sendCMDWithOutData(device, request);
long responseCode = response.code;
}
@Test
public void testGetStorageIDs() throws COMException {
MTPDataset request = new MTPDataset(0x1004);
MTPDataset response = MTPHelper.getInstance().sendCMDWithInData(device, request);
byte[] storageIdArr = response.data;
long responseCode = response.code;
}
2.Register MTP Event
MTPHelper.getInstance().registerEvent(device, new MTPHelper.EventListener() {
@Override
public void onEvent(MTPDataset event, Exception e) {
if (e != null) {
e.printStackTrace();
return;
}
//mtp event,example object added...
}
});