android - Detecting incoming call -
this question has answer here:
here, i'm creating application start flash when sms recieved , incoming call recieved. flash working on recieving sms not on call, why? can help? i'm stuck on since many days. in advance, code given below. flash performs on recieving sms not on recieving calls. expecting guidence. when searched regarding getting classes , methods create own app. requesting explanation
public class smsreceiver extends broadcastreceiver { boolean call; private camera camera; int count; long delaytime; editor editor; string flashtype; private boolean hasflash; private boolean isflashon; private boolean isflashblinking; private boolean mactive; private handler mhander; private final runnable mrunnable; private boolean mswap; private context mcontext; audiomanager myaudiomanager; string noofblinks; int numbofblink; parameters params; sharedpreferences pref; stringbuilder result; boolean ring; boolean silent; boolean sms; string timetoblink; boolean vibrate; public class phonelistener extends phonestatelistener { private context context; public phonelistener(context c) { log.i("callrecorder", "phonelistener constructor"); this.context = c; } public void oncallstatechanged(int state, string incomingnumber) { switch (state) { case 0: try { smsreceiver.this.mhander .removecallbacks(smsreceiver.this.mrunnable); if (smsreceiver.this.camera != null) { smsreceiver.this.camera.release(); } } catch (exception e) { try { smsreceiver.this.camera.release(); } catch (exception e2) { } } case 1: try { if (smsreceiver.this.call.booleanvalue()) { if (smsreceiver.this.myaudiomanager.getringermode() == 0 && smsreceiver.this.silent.booleanvalue()) { smsreceiver.this.flash(); } if (smsreceiver.this.myaudiomanager.getringermode() == 1 && smsreceiver.this.vibrate.booleanvalue()) { smsreceiver.this.flash(); } if (smsreceiver.this.myaudiomanager.getringermode() == 2 && smsreceiver.this.ring.booleanvalue()) { smsreceiver.this.flash(); } } } catch (exception e3) { } case 2: try { smsreceiver.this.mhander .removecallbacks(smsreceiver.this.mrunnable); if (smsreceiver.this.camera != null) { smsreceiver.this.camera.release(); } } catch (exception e4) { try { smsreceiver.this.camera.release(); } catch (exception e5) { } } default: } } } public smsreceiver() { this.mhander = new handler(); this.mactive = false; this.mswap = true; this.isflashblinking = true; this.count = 0; this.mrunnable = new runnable() { @override // todo auto-generated method stub public void run() { try { smsreceiver smsreceiver = smsreceiver.this; smsreceiver.count++; } catch (exception e) { } if (smsreceiver.this.mactive) { if (smsreceiver.this.count >= smsreceiver.this.numbofblink * 2) { try { smsreceiver.this.mhander .removecallbacks(smsreceiver.this.mrunnable); smsreceiver.this.camera.release(); } catch (exception e2) { } } if (smsreceiver.this.isflashon) { smsreceiver.this.turnoffflash(); } else { smsreceiver.this.turnonflash(); } try { smsreceiver.this.mhander.postdelayed( smsreceiver.this.mrunnable, smsreceiver.this.delaytime); } catch (exception e3) { } } } }; } public void onreceive(context context, intent intent) { try { this.mcontext = context; this.count = 0; try { this.pref = preferencemanager .getdefaultsharedpreferences(this.mcontext); this.editor = this.pref.edit(); this.call = boolean.valueof(this.pref.getboolean("call", true)); this.sms = boolean.valueof(this.pref.getboolean("sms", true)); this.timetoblink = this.pref.getstring("blinktime", "200"); this.noofblinks = this.pref.getstring("noofblinks", "5"); this.ring = boolean.valueof(this.pref.getboolean("ring", true)); this.vibrate = boolean.valueof(this.pref.getboolean("vibrate", true)); this.silent = boolean.valueof(this.pref.getboolean("silent", true)); this.flashtype = this.pref.getstring("flashtype", "1"); this.delaytime = long.parselong(this.timetoblink); this.numbofblink = integer.parseint(this.noofblinks); this.myaudiomanager = (audiomanager) this.mcontext .getsystemservice("audio"); } catch (exception e) { } ((telephonymanager) this.mcontext.getsystemservice("phone")) .listen(new phonelistener(context), 32); } catch (exception e2) { } } public void flash() { try { this.hasflash = this.mcontext.getpackagemanager().hassystemfeature( "android.hardware.camera.flash"); if (this.hasflash) { getcamera(); startstrobe(); return; } alertdialog alert = new builder(this.mcontext).create(); alert.settitle("error"); alert.setmessage("sorry, device doesn't support flash light!"); alert.setbutton("ok", new onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { // todo auto-generated method stub } }); alert.show(); } catch (exception e) { } } private void getcamera() { if (this.camera == null) { try { this.camera = camera.open(); this.params = this.camera.getparameters(); } catch (exception e) { log.e("camera error. failed open. error: ", e.getmessage()); } } } private void turnonflash() { try { if (!this.isflashon && this.camera != null && this.params != null) { this.params = this.camera.getparameters(); if (this.flashtype.equals("2")) { this.params.setflashmode("torch"); } else if (this.flashtype.equals("3")) { this.params.setflashmode("torch"); } else { this.params.setflashmode("torch"); } this.camera.setparameters(this.params); this.camera.startpreview(); this.isflashon = true; } } catch (exception e) { } } private void turnoffflash() { try { if (this.isflashon && this.camera != null && this.params != null) { this.params = this.camera.getparameters(); this.params.setflashmode("off"); this.camera.setparameters(this.params); this.camera.stoppreview(); this.isflashon = false; } } catch (exception e) { } } private void startstrobe() { try { this.mactive = true; this.mhander.post(this.mrunnable); } catch (exception e) { } } }
this doable
follow link same
Comments
Post a Comment