https://static.06ms.com/static/images/index/19.jpg

ROOT模式下,接听来电的方法。

使用了Root Tools 来招待命令。https://code.google.com/p/roottools/

/**
 * 接听来电
 */
private void answerRingingCall()
{
    try
    {
        Command command = new Command(0, "input keyevent 5")
        {
            @Override
            public void output(int id, String line)
            {
                Log.d(Tag, line);
            }
        };
        RootTools.getShell(true).add(command).waitForFinish();
    }
    catch (InterruptedException e)
    {
        e.printStackTrace();
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
    catch (TimeoutException e)
    {
        e.printStackTrace();
    }
    catch (RootDeniedException e)
    {
        e.printStackTrace();
    }
}

https://static.06ms.com/static/images/index/16.jpg

安卓来电静音

来电铃声响起后,可通过此代码实现静音而非挂断。

private static int previousMuteMode = -1;

/**
 * 来电静音
 * 
 * @param context
 */
private void toggleRingerMute(Context context)
{
    AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    if (previousMuteMode == -1)
    {
        previousMuteMode = am.getRingerMode();
        am.setRingerMode(0);
    }
    am.setRingerMode(previousMuteMode);
    previousMuteMode = -1;
}

https://static.06ms.com/static/images/index/19.jpg

安卓通话免提切换

实现免提开启和关闭,需要添加的权限

/**
 * 免提
 * 
 * @param context
 */
private void toggleSpeaker(Context context)
{
    AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    am.setMode(AudioManager.MODE_IN_CALL);
    am.setSpeakerphoneOn(!am.isSpeakerphoneOn());
}