java - End incoming call when sensor receives certain value android -
i'm trying implement program ends call when magnetic field sensor has been changed value. have managed display toast show application detect when app open. want expand that:
- when checkbox ticked, runs in background service (i'm not sure i've called service stuff correctly)
- the sensor should listening when there incoming call.
basically, want on sensor changed class called when box checked , call ringing, , application should check when app not open.
public class mainactivity extends activity implements sensoreventlistener { checkbox calls, texts, events; textview one, two, three; sensormanager sm; sensor sensor; float sensorx, sensory, sensorz, sensorx2, sensory2, sensorz2; float ex, why, zed, diff, mdiff; int count; telephonymanager tm; audiomanager audio; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main_activity); linktoxml(); sensorx = sensory = sensorz = sensorx2 = sensory2= sensorz2=0; mdiff = -30; diff = 30; count = 0; calls.setoncheckedchangelistener(new oncheckedchangelistener() { public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { //turn on call magnets if (calls.ischecked()){ startservice(new intent()); if(telephonymanager.extra_state.equals(telephonymanager.extra_state_ringing)) { sm = (sensormanager) getsystemservice(context.sensor_service); sensor = sm.getdefaultsensor(sensor.type_magnetic_field); sm.registerlistener(mainactivity.this, sensor, sensormanager.sensor_delay_fastest); audio = (audiomanager)getsystemservice(context.audio_service); //start listener magnet //toast.maketext(getapplicationcontext(),"phone riging", toast.length_long).show(); } }else{ stopservice(new intent()); } } }); }
Comments
Post a Comment