android - How to keep flash on when activity goes to background -


i developing simple flashlight application, while have achieved looking for, perform way want to. flashlight remains on while activity active, hit home button minimize activity flashlight turns off. want flashlight stay on , turn off when click turn off button in activity.

i want if flashlight active , user hits home button minimize activity, turn off button displayed in notification bar.

please guide me.

please try use bellow code.

public class customflashlight {

private static customflashlight instance;  private static camera mcamera;   public static customflashlight getinstance() {     if (null == instance) {         instance = new customflashlight();     }     return instance; }  public static boolean checkflashavailaibility(context context) {     boolean flag = false;     try {         flag = context.getpackagemanager().hassystemfeature(                 packagemanager.feature_camera_flash);     } catch (exception e) {         e.printstacktrace();     }     return flag; }  public static boolean turnonlight() {     boolean flag = false;     try {         mcamera = camera.open();         if (mcamera != null) {             parameters params = mcamera.getparameters();             if (build.model.equals("gt-p1000")) {                 params.setflashmode(parameters.flash_mode_on);             } else {                  params.setflashmode(parameters.flash_mode_torch);             }             mcamera.setparameters(params);             mcamera.startpreview();             mcamera.autofocus(new autofocuscallback() {                  public void onautofocus(boolean success, camera camera) {                 }             });              flag = true;         } else {             flag = false;         }     } catch (exception e) {         e.printstacktrace();      }     return flag; }  public static boolean turnofflight() {     boolean flag = false;     try {         if (mcamera != null) {             mcamera.stoppreview();             mcamera.release();             mcamera = null;             flag = true;         }     } catch (exception e) {         e.printstacktrace();      }     return flag; } 

}


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -