Colleagues, it became necessary to pick up the phone during a call from the application

Googling suggested a solution, but in my case it does not work for 4.0

Manifest permissions:

<uses-permission android:name="android.permission.READ_PHONE_STATE"/> 

The class itself:

 public class Controller { private static final String TAG = "CONTROLLER_1"; private static Boolean flag = false; private static Context contextApp; private enum methods{accept, abort} public static void setFlag(Boolean value){flag = value;} public static void mergeMethod(String command, Context context){ contextApp = context; if (command.equals(methods.accept.name())) { acceptCall(); } } private static void acceptCall(){ Log.d(TAG, "acceptCall"); if (flag) { Log.d(TAG, "SUCCESS"); Intent headSetUnPluggedintent = new Intent(Intent.ACTION_HEADSET_PLUG); headSetUnPluggedintent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); headSetUnPluggedintent.putExtra("state", 1); headSetUnPluggedintent.putExtra("name", "Headset"); try { contextApp.sendOrderedBroadcast(headSetUnPluggedintent, null); } catch (Exception e) { e.printStackTrace(); } Intent putBtn = new Intent(Intent.ACTION_MEDIA_BUTTON); putBtn.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK)); try { Log.d(TAG, "onAccept"); contextApp.sendOrderedBroadcast(putBtn, "android.permission.CALL_PRIVILEGED"); } catch (Exception e){ e.printStackTrace(); } flag = !flag; } } } 

Can you tell me the reason?

  • one
    Here the problem is described in detail: Answer - ivan

0