You can use ContentProvider
like a REST webinterface
From apps:
Uri ledUri = Uri.parse("content://your.app/led");
ContentResolver cr = getContentResolver();
// "write" data
ContentValues cv = new ContentValues();
cv.put("state", 1);
cr.insert(ledUri, cv);
// read data
int newState = 0;
Cursor c = cr.query(ledUri, new String[] { "state" }, null, null, null);
if (c.moveToFirst()) {
newState = c.getInt(0);
}
Inside your provider, instead of writing data into a database you simply set / read GPIO states. Roughly like
@Override
public Uri insert(Uri uri, ContentValues values) {
if (uri.toString().equals("content://your.app/led")) {
int requestedState = values.getAsInteger("state");
set_gpio_state(requestedState);
}
}
How to acccess GPIOs from Java is another question since they are (AFAIK) only accessible on kernel level.