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

converting an array of integers into one long integer
Neo4j OGM fields not inherited
doesn't compile: sparkjava exception handling
Decode polynomial from String with Pattern and Matcher
how to set path for executable IE 11 drivers
How to fix this with Retrfit 2.0
How to initialize log4j2 using log4j.configurationFile in java-vm-args of Java Web Start application (JNLP)
The Anonymous Visitor
How to specify multiple input paths to a Dataflow job
How to reduce response time while using hibernate
How to use version in REST API with spring mvc?
How to Group Documents by a Field and Calculate Count in mongodb using java [closed]
Java: Applying probability constraints on Random() [closed]
Testng Absent Code attribute in method that is not native or abstract in class file
convert “Nested ArrayList XML” to java Object using Two Custom Converters of XStream
Java 8 Stream - check if instanceof

Categories

HOME
coq
zeromq
openstack
push-notification
smarty
homebrew
tizen-web-app
cakephp-2.5
ip
angular-ui-bootstrap
fingerprint
mvvmcross
yum
azure-storage-tables
bs4
ssl-client-authentication
reveal.js
google-cloud-spanner
clojurescript
pugjs
firefox-webextensions
jprofiler
introduction
dbext
visjs
riot.js
csrf-protection
facebook-instant-articles
wkwebview
apache-commons-io
chromebook
internet-explorer-9
bootstrap-material-design
applozic
elasticsearch-net
log4js-node
newline
tinymce-4
javascriptcore
data-manipulation
catel
stringtemplate
textmate
accelerate-framework
mozilla
jmonkeyengine
xenforo
awt
avro4s
keydown
total-commander
outlook-2013
strptime
revapi
jquery-validate
clean-architecture
nstextview
knpmenubundle
nbconvert
spring-mongodb
smart-table
objective-c-swift-bridge
xcb
visual-c++-2008
setuptools
nxt
azure-sdk
autorest
pickadate
livequery
itextpdf
javax.sound.midi
teamcity-8.0
metaclass
fouc
wyam
sframe
deis
cakephp-3.1
service-accounts
fluid-dynamics
cisco-ios
bridge.net
android-nested-fragment
client-side-templating
neolane
inbox
eventlistener
referrer
armcc
viewswitcher
boost-filesystem
mercurial-server
nsobject
spyware
genshi
file-comparison
appendto
iphone-web-app
w3wp.exe
backcolor
genealogy
dbisam
rtml

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