So the logic is:
- User connects a USB to Android device.
- User press "Find Update" button.
- The App connects to the USB and finds in the main folder any .apk file.
- The App opens the .apk file found in the USB.
- The .apk runs and update the current App.
What I have so far:
findUpdate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
boolean foundUsb = false;
usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
deviceList = usbManager.getDeviceList();
deviceIterator = deviceList.values().iterator();
Log.d("UPDATER", "Pressed");
while(deviceIterator.hasNext()){
UsbDevice device = deviceIterator.next();
Log.d("UPDATER", "Device Attached: " + device.getManufacturerName());
if (!Objects.equals(device.getManufacturerName(), gv.getManufacturerIDPlaca())) {
Log.d("UPDATER", device.getManufacturerName());
foundUsb = true;
PendingIntent mPermissionIntent = PendingIntent.getBroadcast(SetupActivity.this, 0, new Intent(ACTION_USB_PERMISSION), 0);
if (!usbManager.hasPermission(device)) {
Log.d("UPDATER", "No access");
usbManager.requestPermission(device, mPermissionIntent);
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
}
Log.d("UPDATER", "Has access");
usbDevice = device;
usbInterface = usbDevice.getInterface(0);
usbEndpoint = usbInterface.getEndpoint(0);
usbDeviceConnection = usbManager.openDevice(usbDevice);
packetSize = usbEndpoint.getMaxPacketSize();
new Thread(new Runnable() {
public void run() {
final byte[] buffer = new byte[packetSize];
usbDeviceConnection.claimInterface(usbInterface, forceClaim);
usbDeviceConnection.bulkTransfer(usbEndpoint, buffer, packetSize, TIMEOUT);
Log.d("UPDATER", String.valueOf(buffer));
}
}).start();
}
}
if (!foundUsb) {
Toast.makeText(context, "No USB detected", Toast.LENGTH_SHORT).show();
}
}
});
What this code returns me in console is a buffer (of bytes) converted to a String.
I'm wondering how could I find a file let's say app.apk and open it to actually update the current app (where the button is pressed from).