name :name : Uses-Feature Uses-Permission
name :name : Uses-Feature Uses-Permission
https://github.com/mik3y/usb-serial-for-android
android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/device_filter" />
Step 5: Create the xml folder, located under the res folder
Step 6: Create the xml file, named device_filter, located in the xml folder. Copy this content to the
device_filter.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- 0x0403 / 0x6001: FTDI FT232R UART -->
<usb-device vendor-id="1027" product-id="24577" />
</resources>
Step 7: Open the build.graddle (module app) to add the usb to uart library
compile 'com.github.mik3y:usb-serial-for-android:2.+'
UsbSerialPort port;
if (availableDrivers.isEmpty()) {
Log.d(TAG, "UART is not available");
}else {
Log.d(TAG, "UART is available");
PendingIntent usbPermissionIntent =
PendingIntent.getBroadcast(this, 0, new
Intent(INTENT_ACTION_GRANT_USB), 0);
manager.requestPermission(driver.getDevice(),
usbPermissionIntent);
manager.requestPermission(driver.getDevice(),
PendingIntent.getBroadcast(this, 0, new
Intent(ACTION_USB_PERMISSION), 0));
return;
} else {
port = driver.getPorts().get(0);
try {
port.open(connection);
port.setParameters(115200, 8,
UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE);
Executors.newSingleThreadExecutor().submit(usbIoManager);
Log.d(TAG, "UART is openned");
} catch (Exception e) {
Log.d(TAG, "There is error");
}
}
}
Step 10: There is an error in step 9 due to missing the uart receiver listener. Please correct this by
following:
public class MainActivity extends Activity implements
SerialInputOutputManager.Listener
@Override
public void onRunError(Exception e) {
Step 12: When you want to send something from the Android device to uart:
port.write("ABC#".getBytes(), 1000);