I've developed an app that listens to the serial ports and I've been using "chmod 666 /dev/ttyS0" for read/write access to the serial port - however - this method relies on "su" and is only temporary.
What needs to be done to gain read/write access to the serial ports permanently ?
Unfortunately you will always require superuser/root access to do this on COTS hardware (but then most off-the-shelf Android devices don't have accessible serial ports).
If you are in control of the device firmware/ROM, you could potentially make other arrangements so that the init.rc file sets ownership of the serial device so that only your app has access, but this seems more difficult than probably necessary.
Your best bet is to require a rooted device, and your app will need to set the permissions on the serial device file every time before it is opened. If your phone has the su app installed (which is typical for rooted Android devices), then your app can easily do this automatically. The first time the app attempts to do this, the user will get a confirmation dialog, but they can check a box so that the decision to allow is remembered.
On a rooted device, you should be able to do something like:
try {
Runtime.getRuntime().exec("su -c 'chmod 666 /dev/ttyS0'");
} catch (IOException e) {
e.printStackTrace();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With