First you need to store the brightness of the screen before flashing in some variable
example float
float oldBrightNess = Settings.System.getInt(getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS);
and set this value to window layout when the state is false.
See the following code it works exactly same way.
If the screen is not flashed then clickin on the button will flash and vice-versa when you click once again
Sample Code
public class RelativeLayoutTesting extends Activity implements OnClickListener {
Button button3;
boolean isPLAYING;
MediaPlayer mp;
boolean isFlashedBefore = false;
float oldBrightNess = 0;
float newBrightNess = 1.0f;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.sample);
button3 = (Button) findViewById(R.id.btn3);
button3.setOnClickListener(this);
try{
oldBrightNess = Settings.System.getInt(getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS);
}catch(Exception ex){
ex.printStackTrace();
oldBrightNess = 1.0f;
}
System.out.println("...Brighness..."+oldBrightNess);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
WindowManager.LayoutParams lp = getWindow().getAttributes();
if(!isFlashedBefore){
lp.screenBrightness = newBrightNess;
}else{
lp.screenBrightness = oldBrightNess;
}
getWindow().setAttributes(lp);
isFlashedBefore = !isFlashedBefore;
// emailWOAttach(RelativeLayoutTesting.this);
}
}