Is there any way to end the call in Android 2.3?

I am trying to develop something similar to AutoAnswer, but it also freezes automatically when a broadcast receiver is notified. I spent all day reading another stackoverflow question on this issue, and it seems that MODIFY_PHONE_STATE permission MODIFY_PHONE_STATE limited by system applications, however some posts say that using endCall (); does not require this permission.

My question has two parts :

This is what my file tree in netbeans looks like:
enter image description here

And this is the code that works in my translator. This has been published many times here before as a solution to this problem, but I still can't get it to work: /

  ITelephony telephonyService; TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); try { Class c = Class.forName(telephony.getClass().getName()); Method m = c.getDeclaredMethod("getITelephony"); m.setAccessible(true); telephonyService = (ITelephony) m.invoke(telephony); telephonyService.endCall(); } catch (Exception e) { //TODO: some exception handling } 

Looking through the logs, I see this error:

 [PhoneIntfMgr] CMD_END_CALL: no call to hang up 

EDIT: I am new to Android development and cannot find console output for Android applications - for example, to call e.printStackTrace (), but I have a toast displaying some text inside the catch block, like this:

 catch (Exception e) { Toast toast = Toast.makeText(context, "IN CATCH BLOCK ", Toast.LENGTH_LONG); toast.show(); e.printStackTrace(); } 

But nothing is displayed on the screen.

+4
source share
1 answer

you can use this code:

 telephonyManager.listen(new PhoneStateListener() { @Override public void onCallStateChanged(int state, String incomingNumber) { switch (state) { case TelephonyManager.CALL_STATE_IDLE: /* your code */ break; case TelephonyManager.CALL_STATE_OFFHOOK: Toast.makeText(context.getApplicationContext(), "OFFHOOK", Toast.LENGTH_SHORT).show(); setResultData(null); break; case TelephonyManager.CALL_STATE_RINGING: /* your code */ break; } // super.onCallStateChanged(state, incomingNumber); } }, PhoneStateListener.LISTEN_CALL_STATE); 

When you are going to the OFFHOOK state, you can see a toast that shows "OFFHOOK" and then setResultData(null); ends the call.

0
source

Source: https://habr.com/ru/post/1416273/


All Articles