Hi Everyone i am making a android app to answer all incoming call through my app i have done nicely for lolipop and below but also want to do that for marshmallow and above , i did lot of R & D but have not found any satisfied solution , so i am asking by my own
Below code is not working for marshmallow and above. This code is working till Lolipop.
  private void acceptCall_n() {
            // for HTC devices we need to broadcast a connected headset
            boolean broadcastConnected = MANUFACTURER_HTC.equalsIgnoreCase(Build.MANUFACTURER)
                    && !audioManager.isWiredHeadsetOn();
            if (broadcastConnected) {
                broadcastHeadsetConnected(false);
            }
            try {
                try {
                    // logger.debug("execute input keycode headset hook");
                    Runtime.getRuntime().exec("input keyevent " +
                            Integer.toString(KeyEvent.KEYCODE_HEADSETHOOK));
                } catch (IOException e) {
                    Log.e("Call Exception ",e.toString());
                    HelperMethods.showToastS(getBaseContext(),"Call Exception one "+e.toString());
                    // Runtime.exec(String) had an I/O problem, try to fall back
                    //    logger.debug("send keycode headset hook intents");
                    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));
                     sendOrderedBroadcast(btnDown, enforcedPerm);
                    sendOrderedBroadcast(btnUp, enforcedPerm);
                }
            }catch (Exception e){
                e.printStackTrace();
                Log.e("Call Exception two",e.toString());
                HelperMethods.showToastS(getBaseContext(),"Call Exception two "+e.toString());
            }finally {
                if (broadcastConnected) {
                    broadcastHeadsetConnected(false);
                }
            }
        }
 
    