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

Tomcat startup takes huge time with my Spring application
Javax mail sendpulse smtp server
Getting weblogic.management.NoAccessRuntimeException on creating webservice of java class
Spring Data + JPA > New entries of “mappedBy” property are not fetched from DB after SQL INSERT
How do I make a .jar file with a .jar file? [closed]
What is the use of inheritance if the same thing can be done by creating package? [closed]
DocumentFilter in java and ctrl+v is not working
how to read the values of Arraylist from Map in java [duplicate]
Why does my converted string continue to append
Exception on using custom title bar android
Difference between Java serialization and Hadoop serialization [duplicate]
Get Bean while destroying
Retrofit - Clarification on how to write with Retrofit
Regex, extract string not between symbols
What if I do not remove context data from MDC?
Problems with Fontsizes with Tesseract

Categories

HOME
winforms
image
openmp
debugging
netbeans
fluentd
dictionary
layout
onedrive
platform-builder
sd-card
framework7
setup-deployment
google-project-tango
disassembler
baqend
mouse
constraint-programming
mapserver
zebra-printers
msp430
circuit
iolanguage
graphlab
saxon
text-rendering
oxyplot
nhibernate-envers
django-cms
clickonce
csrf-protection
zurb-foundation-6
underflow
social-media
fifo
strncpy
neo4j-spatial
msys2
large-file-upload
gsmcomm
preg-match
nameservers
ecto
uisplitview
karaf
code-contracts
avcapturesession
phpfreechat
repo
openoffice.org
wallpaper
normal-distribution
environment-modules
picasso
espeak
android-browser
graphenedb
awt
elmah
flashair
babel-core
fancybox-2
elgg
carrot
sqlbulkcopy
titanium-android
redundancy
smart-table
deadbolt-2
google-web-starter-kit
player
testng-dataprovider
rvest
php-internals
kendonumerictextbox
rtbkit
wso2cloud
lib.web.mvc
teamcity-8.0
iis-arr
security-testing
cisco-ios
census
remobjects
c++03
codeigniter-url
qcodo
applescript-objc
contenttype
bundles
fmod
prettify
tidy
odata4j
rabl
chronoforms
yui-compressor
sqlperformance
flashvars
kyotocabinet
multipage
labwindows
spring-portlet-mvc
cufon
boost-filesystem
mod-auth
celltable
jmock
w3wp.exe
cxxtest
mirah
castle-monorail
perfect-hash
audio-capture
boost-smart-ptr
gacutil
ubuntu-9.04
windows-live-messenger

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App