0% found this document useful (0 votes)
20 views2 pages

Camera Isflashlighton Params: Setcontentview (R.Layout - Camera)

This Android code defines a Cameratorch class that extends the Activity class. The onCreate method initializes the camera and checks if the device has a flash. It calls methods to turn the flash light on and off. The setFlashlightOn and setFlashlightOff methods set the camera parameters to toggle the flash mode between torch and off, and start/stop the camera preview accordingly. On stop, the camera is released.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views2 pages

Camera Isflashlighton Params: Setcontentview (R.Layout - Camera)

This Android code defines a Cameratorch class that extends the Activity class. The onCreate method initializes the camera and checks if the device has a flash. It calls methods to turn the flash light on and off. The setFlashlightOn and setFlashlightOff methods set the camera parameters to toggle the flash mode between torch and off, and start/stop the camera preview accordingly. On stop, the camera is released.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

import

import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import

android.app.Activity ;
android.content.Context;
android.content.pm.PackageManager;
android.hardware.Camera;
android.os.Bundle ;
android.app.Activity ;
android.os.Bundle ;
android.os.PowerManager;
android.util.Log;
android.view.View ;
android.widget.AdapterView ;
android.widget.ArrayAdapter ;
android.widget.LinearLayout ;
android.widget.ListView ;
android.widget.SimpleAdapter ;
android.widget.Toast ;
java.util.ArrayList ;
java.util.HashMap ;
java.util.List ;
java.util.Map ;
java.util.Timer;
java.util.TimerTask;

public class cameratorch extends Activity {


private Camera camera;
private boolean isFlashlightOn;
Camera.Parameters params;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState) ;
setContentView(R.layout.camera) ;
boolean isCameraFlash =
getApplicationContext().getPackageManager()
.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
if(!isCameraFlash) {
// showCameraAlert();
} else {
camera = Camera.open();
params = camera.getParameters();
if(isFlashlightOn) {
setFlashlightOff();
} else {
}

setFlashlightOn();

}
}
private void setFlashlightOn() {
params = camera.getParameters();
params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
camera.setParameters(params);
camera.startPreview();
isFlashlightOn = true;
}
private void setFlashlightOff() {
params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
camera.setParameters(params);
camera.stopPreview();
isFlashlightOn = false;
}
protected void onStop() {
super.onStop();

}
}
!

if(camera != null) {
camera.release();
camera = null;
}

You might also like