Code example for UsbManager

Methods: getAccessoryList, openAccessory

0
		if (mInputStream != null || mOutputStream != null) {
			Log.d(TAG, "already connected");
			return; 
		} 
 
		UsbAccessory[] accessories = usbManager.getAccessoryList();
		mAccessory = (accessories == null ? null
				: accessories[0]);
		if (mAccessory == null) {
			Toast.makeText(this, "No TinyG USB accessory devices attached!", Toast.LENGTH_SHORT).show();
			return; 
		} 
		mFileDescriptor = usbManager.openAccessory(mAccessory);
		if (mFileDescriptor != null) {
			FileDescriptor fd = mFileDescriptor.getFileDescriptor();
			if (fd.valid()) {
				mInputStream = new FileInputStream(fd);
				mOutputStream = new FileOutputStream(fd);
			} else { 
				Log.d(TAG, "FD for accessory not valid!");
			}