//打开扬声器
public void OpenSpeaker() {
try{
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
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,"揚聲器已經關閉",Toast.LENGTH_SHORT).show();
}
setSpeakerphoneOn() only work when audio mode set to MODE_IN_CALL. Try this:
AudioManager audioManager = (AudioManager)mActivity.getSystemService(Context.AUDIO_SERVICE); audioManager.setMode(AudioManager.MODE_IN_CALL); audioManager.setSpeakerphoneOn(true);
Please remember set back to normal mode before you quit.
Your code needs to have android.permission.MODIFY_AUDIO_SETTINGS permission set in your manifest file because setSpeakerPhoneOn() requires that permission.
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.fwqtg.net
思路: 将输入的要插入的数m依次和数组中的元素进行比较。 思: 在排好序的数组中,从右往左比较还是从左往右比较? 其实都可以,但是我觉得从右边(也就是最大的数)依次开始比较,程序比较简单些。 从最大的数也就是数组组下标为n-1的元素比较,若是m<a[n-1],…