java


Changing content of system file using Process output stream [Android]


I'm writing an application that changes brightness of screen (by writing proper value to file "/sys/class/leds/wled/brightness") to value passed by user.
The problem is following: application works correctly only once (changes the brightness), after second try debugger says: java.io.IOException: write failed: EBADF (Bad file number).
How can I solve this problem? The Android version application is started on - 4.1. Thank you for reading this and helping me...
private Process rootProcess = null;
//called after application starts
private void getRootAccess() {
try {
rootProcess = Runtime.getRuntime().exec("su");
}catch(IOException e) {
Toast toast = Toast.makeText(this, "Could not get root access! Exiting.", Toast.LENGTH_LONG);
toast.show();
System.exit(1);
}
}
//called every time when an user clicks the button
private void writeBrightnessValueToFile(int brightnessValue) {
String targetFilename = "/sys/class/leds/wled/brightness";
String commandToExecute ="echo " + Integer.toString(brightnessValue) + " > " + targetFilename;
try {
OutputStream outputToFile = rootProcess.getOutputStream();
outputToFile.write(commandToExecute.getBytes());
outputToFile.flush();
outputToFile.close();
}catch(IOException e) {
Toast message = Toast.makeText(this, "Couldn't change the brightness!", Toast.LENGTH_LONG);
message.show();
e.printStackTrace();
}
}

Related Links

Manually adding days to date?
Add Calendar event with alarm from BroadcastReceiver Android
Spring MVC3 + Apache tiles + Thymeleaf Integration Issue
Jersey client (2.x) does not send my GET request headers
My JOptionPane In Java Doesn't Continue To The Next Window?
Convert Key and Value from input JSON to Guava ListMultimap?
How can i check if a variable is inside a range of numbers in a parameterized JUnit Test
How to avoid java.util.zip.ZipException in Android studio at build time
Android Marshmallow custom calendar / date picker
Transactions are not rollbacking in quartz when spring #Transactional is used
Java method with different get and return types
Timestamp.getTime() considers the timestamp value as time in system time zone
How to add resources created by idlj-maven-plugin to the generate-sources phase
Java Swing: JTextArea not working inside JScrollPane
HikariCP: Postgres timestamptz column timezone disappears in resultset of PreparedStatement after 5 queries
Passing List<classname> to ArrayAdapter

Categories

HOME
ms-access
image
oracle11g
image-processing
minimum-spanning-tree
azure-data-factory
reserved
fft
google-oauth
paw-app
leon
jpeg
alpha
cross-browser
fingerprint
indesign
dacpac
windows-10-universal
windows-phone-7
google-cloud-speech
openedx
django-cms
amazonsellercentral
javacv
fopen
assistant
opentype
large-file-upload
subdomains
delicious-api
r-raster
webtest
accelerate-framework
environment-modules
stacked
az-application-insights
jna
texmaker
flickr-api
chain-builder
clean-architecture
tizen-native-app
jxcore
r-forge
crosswalk-runtime
angular-strap
probability-density
login-control
nsfilemanager
freedesktop.org
google-places
eclipse-clp
content-length
kcachegrind
splash
ios9.1
myo
pick
tablelayout
coldbox
qcodo
xcode-6.2
googlemock
starcluster
resty-gwt
viadeo
pyhdf
page-layout
sitemesh
blending
buster.js
padarn
pushbackinputstream
ember-app-kit
specification-pattern
simba
bluepill
gdata-api
manchester-syntax
armcc
stage
spyware
subgurim-maps
infobox
tomcat-valve
servicehost
netbeans-7.1
krl
android-sdk-2.1
wise
jquery-ui-droppable
nhibernate.search
perfect-hash
zend-tool

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App