android_study_2
This is an old revision of the document!
Table of Contents
Android Study 2
Things I have done in my apps.
NFC
BLE
Service
Driver for USB to serial Device
FTSLink by Redpark
In the app the manifest enables USB attach and detach intents to be delivered.
* Asked for permission:
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION); this.parent.getParentContext().getApplicationContext().registerReceiver(mUsbReceiver, filter);
- ACTION_USB_ACCESSORY_ATTACHED re-starts the activity
- ACTION_USB_ACCESSORY_DETACHED is received in a BroadcastReceiver:
private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.v(debugTag, "ACTION: " + action);
if (action.equals(UsbManager.ACTION_USB_ACCESSORY_DETACHED)) {
Log.v(debugTag, "Closing Accessory");
closeAccessory();
}
}
};
- Upon attach, connect to the Device
UsbAccessory[] accessories = mUSBManager.getAccessoryList();
// There is only one USB, this must be the first one
UsbAccessory accessory = (accessories == null ? null : accessories[0]);
if (accessory != null) {
Log.v(FTSLinkServer.debugTag, "Accessory found, try to connect....");
RPUsbConnection connection = new RPUsbConnection(mUSBManager, accessory);
ParcelFileDescriptor mFileDescriptor = usbManager.openAccessory(accessory);
FileDescriptor fd = mFileDescriptor.getFileDescriptor();
mInputStream = new FileInputStream(fd);
mOutputStream = new FileOutputStream(fd);
... Create threads
}
android_study_2.1583807221.txt.gz · Last modified: 2020/03/10 02:27 by jrseti