How change UART default baud rate in Android?

Hello, the default UART speed in Android is 115200, how or where can I change it??

I just added android-serialport-api to Android Studio, anyone know how can I get ttyS0 data to string with this??? Any guide??

hello,try this code please:

public SerialPort getSerialPort() throws SecurityException, IOException, InvalidParameterException {
if (mSerialPort == null) {
    /* Read serial port parameters */
    SharedPreferences sp = getSharedPreferences("android_serialport_api.sample_preferences", MODE_PRIVATE);
    String path = sp.getString("DEVICE", "");
    int baudrate = Integer.decode(sp.getString("BAUDRATE", "-1"));

    /* Check parameters */
    if ( (path.length() == 0) || (baudrate == -1)) {
        throw new InvalidParameterException();

    /* Open the serial port */
    mSerialPort = new SerialPort(new File(path), baudrate, 0);
return mSerialPort;

Hi ZB,

If I put your code directly with a copy-paste, Studio say that the variable ‘mSerialPort’ might not have been initialized. I noticed that in the Serialportexample, the “R.” class isn’t recogniced. Where can I find a good guide to use this api?

I need to show the received data into a textview, finally I get it working with a USBserialdongle + the USBSerial library but not with Serialport_api + ttyS0.

Now I am receiving data in a TextView with the USB dongle, but I only can see a few received lines because when the received data is larger than the TextView box space, the TextView can’t display them. I think that I need do the textview auto scrollable or something similar.

Pls, could anyone help me?

sorry,you need to define the mSerialport:

private SerialPort mSerialPort = null;

for this code you could see here: