package com.lyq.autocall;

import android.content.Context;
import android.media.AudioManager;

public class ManageCall {
	static String TAG = "PhoneUtils";
	private Context mContext;
	private int currVolume;

	//´ò¿ªÑïÉùÆ÷
	public void OpenSpeaker() {

		try {
			AudioManager audioManager = (AudioManager) mContext
					.getSystemService(Context.AUDIO_SERVICE);
			audioManager.setSpeakerphoneOn(true);
			//			audioManager.setMode(AudioManager.ROUTE_SPEAKER);
			currVolume = audioManager
					.getStreamVolume(AudioManager.STREAM_VOICE_CALL);

			if (!audioManager.isSpeakerphoneOn()) {
				audioManager.setSpeakerphoneOn(true);

				audioManager
						.setStreamVolume(
								AudioManager.STREAM_VOICE_CALL,
								audioManager
										.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL),
								AudioManager.STREAM_VOICE_CALL);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	//¹Ø±ÕÑïÉùÆ÷
	public void CloseSpeaker() {

		try {
			AudioManager audioManager = (AudioManager) mContext
					.getSystemService(Context.AUDIO_SERVICE);
			if (audioManager != null) {
				if (audioManager.isSpeakerphoneOn()) {
					audioManager.setSpeakerphoneOn(false);
					audioManager.setStreamVolume(
							AudioManager.STREAM_VOICE_CALL, currVolume,
							AudioManager.STREAM_VOICE_CALL);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		//Toast.makeText(context,"“PÂ•Æ÷ÒÑ½›êPé]",Toast.LENGTH_SHORT).show();
	}
}
