java


Android - using a button to change the screen's brightness


int BrightnesValue= 0;
try {
BrightnesValue = Settings.System.getInt(
getContentResolver(), Settings.System.SCREEN_BRIGHTNESS);
} catch (Settings.SettingNotFoundException e) {
e.printStackTrace();
}
int SysBackLightValue = BrightnesValue-25;
android.provider.Settings.System.putInt(getContentResolver(),
android.provider.Settings.System.SCREEN_BRIGHTNESS,
SysBackLightValue);
I want to change the system's brightness programmatically using a button on the toolbar as shown in the image here. Such that, when clicked for the first time, the brightness reduces, when clicked a second time, the brightness is restored to default.
You can set screen BRIGHTNESS button click
FIRST WAY:
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
int curBrightnessValue=android.provider.Settings.System.getInt(
getContentResolver(),android.provider.Settings.System.SCREEN_BRIGHTNESS);
setBrightness(curBrightnessValue-25);//set BRIGHTNESS
}
private void setBrightness(int brightness) {
try {
IHardwareService hardware = IHardwareService.Stub.asInterface(
ServiceManager.getService("hardware"));
if (hardware != null) {
hardware.setScreenBacklight(brightness);
}
} catch (RemoteException doe) {
}
Manifest.xml
<uses-permission android:name="android.permission.HARDWARE_TEST"></uses-permission>
SECOND WAY:
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
int curBrightnessValue=android.provider.Settings.System.getInt(
getContentResolver(),android.provider.Settings.System.SCREEN_BRIGHTNESS);
int SysBackLightValue = curBrightnessValue-25;
android.provider.Settings.System.putInt(getContentResolver(),
android.provider.Settings.System.SCREEN_BRIGHTNESS,
SysBackLightValue);
}
AndroidManifest.xml:
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>

Related Links

How to check whether two properties objects overlaps or not in java?
Color of a pixel independently of the browser and resolution
Serialize JSON property from inside another property
Calculating incremental average using java
Making a bean primary without annotation or xml config
java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.String
Java Generics and A implements B
How to create a temporary database with postgresql initdb?
I'm trying to write a method that reads a text file and, for each line, prints out the number of words in the line
Spring StreamingResponseBody Request Thread not cleaned up, when client closes connection
Memory leak when I am using Leptonica (lept4j library)
Error deploying to a jbossfuse 6.3 server with Developer profile
Create objects in GenericObjectPool
java program not including all coin types when returning change amount
JAVA - Concurrency - multi-producer/multi-consumer request and response queue
Java - Trees, return the maximum amount of nodes within an arrayList

Categories

HOME
openlayers
path-finding
cmd
youtube-api-v3
gps
disassembler
convolution
indesign
google-cloud-ml
hapi
percona
ghc
pugjs
google-cloud-speech
viewport
cultureinfo
qhull
virtualdub
elasticsearch-ruby
buck
msys2
flink-streaming
frame
http-status-code-503
siesta-swift
code-contracts
avcapturesession
windows-dev-center
android-kernel
wpf-controls
neuroscience
unobtrusive-validation
greenrobot-eventbus
user-controls
fedex
eigenvalue
multipeer-connectivity
jlink
fancybox-2
composite-key
dtexec
flow-control
imanage
spring-cache
background-service
time-and-attendance
mongocsharpdriver
multiple-regression
pagedlist
qcustomplot
bluegiga
livequery
vhd
fouc
ionic
pretty-print
notify
block-device
offloading
gadt
document-classification
flask-cors
braille
app42
stxxl
intentservice
mcts
xsockets.net
android-screen-support
jelly
venn-diagram
pysimplesoap
ocx
appender
google-friend-connect
bespin
adrotator
scripting-languages

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