android实现来电静音示例(监听来电)

时间:2022-09-20 13:23:44
复制代码 代码如下:

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;
}