android - Unable to open camera flash during call -
i trying build app camera flash happen in call , sms incoming activity. camera flash not opening during call...i have written simple program.
public class mainactivity extends activity { ..... .... public static class alerthandler extends broadcastreceiver { @override public void onreceive(context context, intent intent) { system.out.println("===inside oneceive"); boolean incomingcall = false; parameters alertparams; camera alertcamera; string callstate = intent.getstringextra(telephonymanager.extra_state); if (null != callstate && callstate.equals(telephonymanager.extra_state_ringing)) { incomingcall = true; } system.out.println("===incomingcall =="+incomingcall); if(incomingcall){ system.out.println("opening camera..."); alertcamera = camera.open(); alertparams = alertcamera.getparameters(); alertparams.setflashmode(parameters.flash_mode_torch); alertcamera.setparameters(alertparams); alertcamera.startpreview(); } } } }
i getting sysout opening camera well, flash. please code fix. no error in logcat.
in play store lot of app present, how work?
use working
public class mainactivity extends actionbaractivity { private static camera camera; // flag detect flash on or off private static boolean islighon = false; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); camera = camera.open(); } public static void toggle() { if (islighon) { log.i("info", "torch turn off!"); final parameters p = camera.getparameters(); p.setflashmode(parameters.flash_mode_off); camera.setparameters(p); camera.stoppreview(); islighon = false; } else { log.i("info", "torch turn on!"); final parameters p = camera.getparameters(); p.setflashmode(parameters.flash_mode_torch); camera.setparameters(p); camera.startpreview(); islighon = true; } } } public class alerthandler extends broadcastreceiver { boolean incomingcall = false; @override public void onreceive(context context, intent intent) { string callstate = intent.getstringextra(telephonymanager.extra_state); if (null != callstate && callstate.equals(telephonymanager.extra_state_ringing)) { incomingcall = true; } if (incomingcall) { mainactivity.toggle(); } else { mainactivity.toggle(); } } }