my requirement accept , disconnect incoming call.
it working fine if call accepted , wait 3 seconds(handler.postdelayed) , disconnecting.
but wanna disconnect call after accepting.(dont wanna wait 3 sconds)
here code. appreciated.
public void acceptanddissconnectcall(final context activity) { int currentapiversion = android.os.build.version.sdk_int; if (currentapiversion >= android.os.build.version_codes.lollipop){ log.i(tag, "it lollipop or greater===="); answercall(activity); } else{ // phones running sdk before lollipop log.i(tag, "this device prior lollipop ===="); acceptcall(activity); } dissconnectcall(activity); } public boolean dissconnectcall(final context activity) { handler handler = new handler(); handler.postdelayed(new runnable() { @override public void run() { try { log.d(tag, "dissconnect call ===== "); // boring old telephonymanager telephonymanager telephonymanager = (telephonymanager) activity.getsystemservice(context.telephony_service); // getitelephony() method class classtelephony = class.forname(telephonymanager.getclass().getname()); method methodgetitelephony = classtelephony.getdeclaredmethod("getitelephony"); // ignore method supposed private methodgetitelephony.setaccessible(true); // invoke getitelephony() itelephony interface object telephonyinterface = methodgetitelephony.invoke(telephonymanager); // endcall method itelephony class telephonyinterfaceclass = class.forname(telephonyinterface.getclass().getname()); method methodendcall = telephonyinterfaceclass.getdeclaredmethod("endcall"); // invoke endcall() methodendcall.invoke(telephonyinterface); } catch (exception ex) { // many things can go wrong reflection calls ex.printstacktrace(); // return false; } // return true; } }, 4000); return false; } public static void acceptcall(context context){ log.d(tag, "accept call ===="); intent buttonup = new intent(intent.action_media_button); buttonup.putextra(intent.extra_key_event, new keyevent(keyevent.action_up, keyevent.keycode_headsethook)); context.sendorderedbroadcast(buttonup, "android.permission.call_privileged"); } public void answercall(final context mcontext) { new thread(new runnable() { @override public void run() { try { log.d(tag, "answer call ===="); runtime.getruntime().exec("input keyevent " + integer.tostring(keyevent.keycode_headsethook)); } catch (ioexception e) { log.e(tag, "ioexception on answercall ========== "); // runtime.exec(string) had i/o problem, try fall string enforcedperm = "android.permission.call_privileged"; intent btndown = new intent(intent.action_media_button).putextra(intent.extra_key_event, new keyevent(keyevent.action_down, keyevent.keycode_headsethook)); intent btnup = new intent(intent.action_media_button).putextra(intent.extra_key_event, new keyevent(keyevent.action_up, keyevent.keycode_headsethook)); mcontext.sendorderedbroadcast(btndown, enforcedperm); mcontext.sendorderedbroadcast(btnup, enforcedperm); } } }).start(); }
in dissconnectcall
method change value 4000
in run method lowest.
handler.postdelayed(new runnable() { @override public void run() { ....... } }, 4000);//decrease value 100
Comments
Post a Comment