How to alter the deprecated Camera class in Android -


in previous way, flashlight feature used using camera class. entire camera , camera-related classes in android.hardware packages deprecated, should alternatively use other classes in android.hardware.camera2 package.

traditionally, coded flashlight part this.

// getting camera parameters private void getcamera() {     if (camera == null) {         try {             camera = camera.open();             params = camera.getparameters();         } catch (runtimeexception e) {             log.e("camera error. failed open. error: ", e.getmessage());         }     } }   /*   * turning on flash   */ private void turnonflash() {     if (!isflashon) {         if (camera == null || params == null) {             return;         }         // play sound         playsound();          params = camera.getparameters();         params.setflashmode(parameters.flash_mode_torch);         camera.setparameters(params);         camera.startpreview();         isflashon = true;          // changing button/switch image         togglebuttonimage();      }   }     

but new api i'm getting confused how use new one. can explain?

for flashlight advise using camera2 api android 6 (api 23), function toggling flashlight looks like

    @targetapi(build.version_codes.m) public void togglemarshmallowflashlight(boolean enable) {     try {         final cameramanager manager = (cameramanager) mcontext.getsystemservice(context.camera_service);         final string[] list = manager.getcameraidlist();         manager.settorchmode(list[0], enable);     } catch (cameraaccessexception e) {      } } 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

android - CollapsingToolbarLayout: position the ExpandedText programmatically -

Listeners to visualise results of load test in JMeter -