android - How to know the outgoing call has answered or not? -
i want know outgoing call answered or not in android program.i want know outgoing call has answered or not.i new in android.please me solve problem.for getting call answered time use this.
i want know outgoing call answered or not in android program. want know outgoing call has answered or not. new in android. please me solve problem. getting call answered time use this.
broadcastreceiver mreceiver = new broadcastreceiver() { @override public void onreceive(context context, intent intent) { if (intent.getaction().equals("android.intent.action.new_outgoing_call")) { savednumber = intent.getextras().getstring("android.intent.extra.phone_number"); } else { string statestr = intent.getextras().getstring(telephonymanager.extra_state); string number = intent.getextras().getstring(telephonymanager.extra_incoming_number); int state = 0; if (statestr.equals(telephonymanager.extra_state_idle)) { state = telephonymanager.call_state_idle; } else if (statestr.equals(telephonymanager.extra_state_offhook)) { state = telephonymanager.call_state_offhook; } else if (statestr.equals(telephonymanager.extra_state_ringing)) { state = telephonymanager.call_state_ringing; } oncallstatechanged(context, state, number); } } }; protected void onincomingcallstarted(context ctx, string number, date start) { } protected void onoutgoingcallstarted(context ctx, string number, date start) { } protected void onincomingcallended(context ctx, string number, date start, date end) { } protected void onoutgoingcallended(context ctx, string number, date start, date end) { simpledateformat localdateformat = new simpledateformat("hh:mm:ss"); startime = localdateformat.format(start); endtime = localdateformat.format(end); long aa = start.gettime(); long bb = end.gettime(); long cc = bb - aa; long diffminutes = cc / 1000 % 60; duration = long.tostring(diffminutes); bundle bundle = new bundle(); bundle.putstring("start", startime); bundle.putstring("end", endtime); bundle.putstring("duration", duration); call_end dfragment = new call_end(); dfragment.setarguments(bundle); dfragment.show(fragmentmanager, "dialog fragment"); } protected void onmissedcall(context ctx, string number, date start) { } public void oncallstatechanged(context context, int state, string number) { if (laststate == state) { //no change, debounce extras return; } switch (state) { case telephonymanager.call_state_ringing: isincoming = true; callstarttime = new date(); savednumber = number; onincomingcallstarted(context, number, callstarttime); break; case telephonymanager.call_state_offhook: callstarttime = new date(); onoutgoingcallstarted(context, savednumber, callstarttime); //transition of ringing->offhook pickups of incoming calls. nothing done on them if (laststate != telephonymanager.call_state_ringing) { isincoming = false; callstarttime = new date(); onoutgoingcallstarted(context, savednumber, callstarttime); } break; case telephonymanager.call_state_idle: //went idle- end of call. type depends on previous state(s) if (laststate == telephonymanager.call_state_ringing) { //ring no pickup- miss onmissedcall(context, savednumber, callstarttime); } else if (isincoming) { onincomingcallended(context, savednumber, callstarttime, new date()); } else { onoutgoingcallended(context, savednumber, callstarttime, new date()); } break; } laststate = state; }
@override public void onreceive(context context, intent intent) { log.d("intent", intent.tostring()); if(intent.getaction().equals("android.intent.action.new_outgoing_call")) { log.e("call_state","outgoing call detected"); } // checking call status try { // telephony manager class object register 1 listner telephonymanager tmgr = (telephonymanager) context.getsystemservice(context.telephony_service); //create listner myphonestatelistener phonelistener = new myphonestatelistener(); // register listener listen_call_state tmgr.listen(phonelistener, phonestatelistener.listen_call_state); } catch (exception e) { e.printstacktrace(); } } private class myphonestatelistener extends phonestatelistener { public void oncallstatechanged(int state, string incomingnumber) { switch (state) { case telephonymanager.call_state_ringing: log.e("call_state","call ringing"); break; case telephonymanager.call_state_offhook: log.e("call_state","call offhook"); break; case telephonymanager.call_state_idle: log.e("call_state","call idle"); break; } } }
wiki
Comments
Post a Comment