D
Deleted member 103
Guest
Hi guys,
can someone convert this source code to B4A?
I know it's a lot, but maybe someone has some time for it.
Thank you very much
Filippo
can someone convert this source code to B4A?
I know it's a lot, but maybe someone has some time for it.
B4X:
/**
* BroadcastReceiver zum Empfangen und Auswerten der USB Erlaubnis aus
* UsbManager.requestPermission(). Wenn die Erlaubnis vom Benutzer erteilt
* wurde, wird die USB Verbindung hergestellt.
*/
private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "mUsbReceiver::onReceive");
String action = intent.getAction();
if (ACTION_USB_PERMISSION.equals(action)) {
synchronized (this) {
UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
Log.d(TAG, "USB permission granted");
if(device != null) {
setDevice(device);
connect();
}
}
else {
Log.d(TAG, "permission denied for device " + device);
}
}
}
}
};
public void onResume() {
super.onResume();
Log.d(TAG, "onResume");
mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
registerReceiver(mUsbReceiver, filter);
Intent intent = getIntent();
Log.d(TAG, "intent: " + intent);
String action = intent.getAction();
UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
setDevice(device);
connect();
} else if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
if (mDevice != null && mDevice.equals(device)) {
disconnect();
}
}
}
Thank you very much
Filippo