Android Call Recording not getting stopped when the call hangs up -


    public class callreceiver extends broadcastreceiver {          mediarecorder callrecorder;         boolean recording = false;         private static boolean ring = false;         private static boolean out = false;         private static boolean callreceived = false;         string outnumber;         location location;          @override         public void onreceive(context context, intent intent) {              if (intent.getaction().equals(intent.action_new_outgoing_call)) {                 outnumber = intent.getstringextra(intent.extra_phone_number);                 log.d("outnumber", outnumber);             }              //check if checked in             sharedpreferences prefs = context.getsharedpreferences("mypreference", context.mode_private);             string check = prefs.getstring("ischeckedin", null);             if (check.equals("yes")) {                  telephonymanager tm = (telephonymanager) context.getsystemservice(context.telephony_service);                 try {                     class c = class.forname(tm.getclass().getname());                     method m = c.getdeclaredmethod("getitelephony");                     m.setaccessible(true);                     //get incoming number , phone state                     bundle bundle = intent.getextras();                     bundle extras = intent.getextras();                     string state = extras.getstring(telephonymanager.extra_state);                     string phonenumber = bundle.getstring("incoming_number"); ``                    log.d("state", state);                     // location                     try {                         locationmanager locationmanager = (locationmanager) context.getsystemservice(context.location_service);                         location = locationmanager.getlastknownlocation(locationmanager.network_provider);                     } catch (exception e) {                         e.printstacktrace();                     }                     //start switch case switch between phone states                     switch (state) {                         //if phone idle                         case "idle":                             toast.maketext(context, state + "", toast.length_short).show();                             //stop recording                             if (recording) {                                 stoprecording();                                 toast.maketext(context, "stopped", toast.length_short).show();                             }                              break;                         //if phone answered                         case "offhook":                             out = true;                             callreceived = true;                             preferenceshelper prefs = new preferenceshelper(context.getapplicationcontext());                             string checked = prefs.getpreferences("ischeckedin");                             if (checked.equals("yes")) {                                 //start recording                                 if (!recording) {                                     startrecording();                                     toast.maketext(context, "started", toast.length_short).show();                                 }                          ring = false;                             }                             break;                         //if phone ringing                         case "ringing":                             toast.maketext(context, state + "" + phonenumber, toast.length_long).show();                             ring = true;                             callreceived = false;                             break;                     }                  } catch (exception e) {                     e.printstacktrace();                 }             }         }//end onreceive          void startrecording() {              string fname = "/sales/rec" + system.currenttimemillis() / 1000 + ".amr";             callrecorder = new mediarecorder();             callrecorder.setaudiosource(mediarecorder.audiosource.voice_call);             callrecorder.setoutputformat(mediarecorder.outputformat.amr_nb);             callrecorder.setaudioencoder(mediarecorder.audioencoder.amr_nb);             callrecorder.setoutputfile(environment.getexternalstoragedirectory().getabsolutepath() + fname);              try {                 callrecorder.prepare();                 callrecorder.start();                 recording = true;             } catch (illegalstateexception e) {                 e.printstacktrace();             } catch (ioexception e) {                 e.printstacktrace();             }          }           void stoprecording() {              callrecorder.stop();             callrecorder.reset();             callrecorder.release();             recording = false;         }     } 

this code , call recording fine problem recording not stop @ time of disconnection , best practice record call or there other stable/safe way same?


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -