I’m using the following code to set the direction of a gpio pin, but getting the following error. Looks like I don’t have enough permissions to write into the gpio files. I already gave full read/write access to all the files as shown below. I’m using targetSdkVersion 22. I greatly appreciate any insights into what I’m missing here. I’m doing the IoT course in Coursera, and I can’t go ahead without accessing the gpios from the code. Thanks again!!
File Permissions
1|shell@msm8916_64:/sys/class/gpio $ ls -l
–w------- root root 4096 1969-12-31 16:00 export
lrwxrwxrwx root root 1969-12-31 16:01 gpio930 → …/…/devices/soc.0/1000000.pinctrl/gpio/gpio930
lrwxrwxrwx root root 1969-12-31 16:01 gpio935 → …/…/devices/soc.0/1000000.pinctrl/gpio/gpio935
shell@msm8916_64:/sys/class/gpio/gpio935 $ ls -l
-rw-r–r-- root root 4096 1969-12-31 16:35 active_low
lrwxrwxrwx root root 1969-12-31 16:35 device → …/…/…/1000000.pinctrl
-rwxrwxrwx root root 4096 1969-12-31 16:40 direction
-rw-r–r-- root root 4096 1969-12-31 16:35 edge
drwxr-xr-x root root 1969-12-31 16:35 power
lrwxrwxrwx root root 1969-12-31 16:35 subsystem → …/…/…/…/…/class/gpio
-rw-r–r-- root root 4096 1969-12-31 16:35 uevent
-rwxrwxrwx root root 4096 1969-12-31 16:41 value
==============================================================================
Code
private void setDirection(String direction) {
Log.v(TAG,“Setting Direction”);
BufferedWriter out = null;
try {
String command = String.format(“echo %s > /sys/class/gpio%s/direction”, direction, this.pin);
Runtime.getRuntime().exec(new String[] {“su”, “-c”, command});
}
catch (IOException e) {
Log.e(TAG,"Error: " + e.getMessage());
}
}
=====================================================================================
Error Message
12-31 17:48:25.510 25294-25294/net.calit2.mooc.iot_db410c.ledblink E/GpioProcessor: Error: Error running exec(). Command: [su, -c, echo out > /sys/class/gpio935/direction] Working Directory: null Environment: null
===================================================================================
Permissions in the manifest file
uses-permission android:name=“android.permission.WRITE_EXTERNAL_STORAGE” />
uses-permission android:name=“android.permission.READ_EXTERNAL_STORAGE” />
uses-permission android:name=“android.permission.WRITE_INTERNAL_STORAGE” />
uses-permission android:name=“android.permission.READ_INTERNAL_STORAGE” />
uses-permission android:name=“android.permission.MOUNT_UNMOUNT_FILESYSTEMS” />