Java Code Examples for android.media.AudioManager#getMode()
The following examples show how to use
android.media.AudioManager#getMode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AutoAnswerReceiver.java From auto-answer with GNU General Public License v3.0 | 6 votes |
@Override public void onReceive(Context context, Intent intent) { // Load preferences SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); // Check phone state String phone_state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); if (phone_state.equals(TelephonyManager.EXTRA_STATE_RINGING) && prefs.getBoolean("enabled", false)) { // Check for "second call" restriction if (prefs.getBoolean("no_second_call", false)) { AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); if (am.getMode() == AudioManager.MODE_IN_CALL) { return; } } // Call a service, since this could take a few seconds context.startService(new Intent(context, AutoAnswerIntentService.class)); } }
Example 2
Source File: AssistantService.java From AssistantBySDK with Apache License 2.0 | 6 votes |
@Override public void execute(AudioManager audioManager) { if (voiceMediator.isBlueToothHeadSet()) { if (!voiceMediator.isSuportA2DP()) { if (audioManager.getMode() != AudioManager.MODE_NORMAL) { Log.e(TAG, "playInChannel>>setMode(AudioManager.MODE_NORMAL)"); audioManager.setMode(AudioManager.MODE_NORMAL); } if (audioManager.isBluetoothScoOn()) { audioManager.setBluetoothScoOn(false); audioManager.stopBluetoothSco(); } } else { if (!audioManager.isBluetoothA2dpOn()) { Log.e(TAG, "playInChannel>>setBluetoothA2dpOn(true)"); audioManager.setBluetoothA2dpOn(true); } } } }
Example 3
Source File: JoH.java From xDrip with GNU General Public License v3.0 | 5 votes |
public static boolean isOngoingCall() { try { AudioManager manager = (AudioManager) xdrip.getAppContext().getSystemService(Context.AUDIO_SERVICE); return (manager.getMode() == AudioManager.MODE_IN_CALL); // possibly should have MODE_IN_COMMUNICATION as well } catch (Exception e) { return false; } }
Example 4
Source File: SoundLogic.java From redalert-android with Apache License 2.0 | 5 votes |
public static int getSoundStreamType(Context context) { // Get the audio manager AudioManager audioManager = (AudioManager) context.getSystemService(context.AUDIO_SERVICE); // In call? if (audioManager.getMode() == AudioManager.MODE_IN_CALL) { // Play in tiny speaker // I think we disabled this because it's played in that speaker already by default // return AudioManager.STREAM_VOICE_CALL; } // Return default stream type return Sound.STREAM_TYPE; }
Example 5
Source File: CallViewActivity.java From matrix-android-console with Apache License 2.0 | 5 votes |
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { // assume that the user cancels the call if it is ringing if (keyCode == KeyEvent.KEYCODE_BACK) { if (!canCallBeResumed()) { if (null != mCall) { mCall.hangup(""); } } else { saveCallView(); } } else if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) || (keyCode == KeyEvent.KEYCODE_VOLUME_UP)) { // this is a trick to reduce the ring volume : // when the call is ringing, the AudioManager.Mode switch to MODE_IN_COMMUNICATION // so the volume is the next call one whereas the user expects to reduce the ring volume. if ((null != mCall) && mCall.getCallState().equals(IMXCall.CALL_STATE_RINGING)) { AudioManager audioManager = (AudioManager) CallViewActivity.this.getSystemService(Context.AUDIO_SERVICE); // IMXChrome call issue if (audioManager.getMode() == AudioManager.MODE_IN_COMMUNICATION) { int musicVol = audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL) * audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC) / audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL); audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, musicVol, 0); } } } return super.onKeyDown(keyCode, event); }
Example 6
Source File: SpeechUtil.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("ConstantConditions") private static boolean isOngoingCall() { final AudioManager manager = (AudioManager) xdrip.getAppContext().getSystemService(Context.AUDIO_SERVICE); try { return (manager.getMode() == AudioManager.MODE_IN_CALL); } catch (NullPointerException e) { return false; } }
Example 7
Source File: JoH.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public static boolean isOngoingCall() { try { AudioManager manager = (AudioManager) xdrip.getAppContext().getSystemService(Context.AUDIO_SERVICE); return (manager.getMode() == AudioManager.MODE_IN_CALL); // possibly should have MODE_IN_COMMUNICATION as well } catch (Exception e) { return false; } }
Example 8
Source File: JoH.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public static boolean isOngoingCall() { try { AudioManager manager = (AudioManager) xdrip.getAppContext().getSystemService(Context.AUDIO_SERVICE); return (manager.getMode() == AudioManager.MODE_IN_CALL); // possibly should have MODE_IN_COMMUNICATION as well } catch (Exception e) { return false; } }
Example 9
Source File: SpeechUtil.java From xDrip with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("ConstantConditions") private static boolean isOngoingCall() { final AudioManager manager = (AudioManager) xdrip.getAppContext().getSystemService(Context.AUDIO_SERVICE); try { return (manager.getMode() == AudioManager.MODE_IN_CALL); } catch (NullPointerException e) { return false; } }
Example 10
Source File: JoH.java From xDrip with GNU General Public License v3.0 | 5 votes |
public static boolean isOngoingCall() { try { AudioManager manager = (AudioManager) xdrip.getAppContext().getSystemService(Context.AUDIO_SERVICE); return (manager.getMode() == AudioManager.MODE_IN_CALL); // possibly should have MODE_IN_COMMUNICATION as well } catch (Exception e) { return false; } }
Example 11
Source File: IflySynthesizer.java From AssistantBySDK with Apache License 2.0 | 5 votes |
/** * 设置默认的合成引擎 * * @param type */ private void setDefaultSynthesizerParam(NetType type) { if (isSpeaking()) { Log.e(TAG, "播放当中切换播放引擎失败"); return; } synthesizer.setParameter(SpeechConstant.SPEED, Integer.toString(mVoiceConfig.getVolSpeed())); synthesizer.setParameter(SpeechConstant.VOLUME, Integer.toString(mVoiceConfig.getVolume())); synthesizer.setParameter(SpeechConstant.VOICE_NAME, mVoiceConfig.getVolName()); synthesizer.setParameter("rdn", "0"); synthesizer.setParameter(SpeechConstant.KEY_REQUEST_FOCUS, "0"); if (mediator.isBlueToothHeadSet()) { synthesizer.setParameter(SpeechConstant.STREAM_TYPE, Integer.toString(AudioManager.STREAM_VOICE_CALL)); } else { synthesizer.setParameter(SpeechConstant.STREAM_TYPE, Integer.toString(AudioManager.STREAM_MUSIC)); AudioManager am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); if (am.getMode() != AudioManager.MODE_NORMAL) { am.setMode(AudioManager.MODE_NORMAL); } } //synthesizer.setParameter(SpeechConstant.ENGINE_TYPE, VoiceConfig.getSynEngineType()); /*if(type==NetType.NETWORK_TYPE_NONE||type==NetType.NETWORK_TYPE_2G){//网络关闭的状态下启动离线识别 Log.e(TAG, "离线。。。。。。。。。。。。。。。。。。。"); synthesizer.setParameter(SpeechConstant.SPEED, OFFLINE_ENGINE_SPPED); synthesizer.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_LOCAL); synthesizer.setParameter(SpeechConstant.VOICE_NAME, "xiaoyan"); isLocalEngine=true; } else{*/ Log.e(TAG, "在线。。。。。。。。。。。。。。。。。。。"); //synthesizer.setParameter(SpeechConstant.SPEED,"70"); synthesizer.setParameter(SpeechConstant.VOICE_NAME, mVoiceConfig.getVolName()); //synthesizer.setParameter(SpeechConstant.VOICE_NAME, ChatRobot.isInit()&&ChatRobot.getInstance().getMode()==ChatConstant.CHILDREN_MODE?"vinn":"vixq"); synthesizer.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_CLOUD); //} }
Example 12
Source File: CallActivity.java From sealrtc-android with MIT License | 5 votes |
private void startBluetoothSco() { AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); if (am != null) { if (am.getMode() != AudioManager.MODE_IN_COMMUNICATION) { am.setMode(AudioManager.MODE_IN_COMMUNICATION); } am.setSpeakerphoneOn(false); am.startBluetoothSco(); } }
Example 13
Source File: AudioManagerUtils.java From DevUtils with Apache License 2.0 | 5 votes |
/** * 获取当前的音频模式 * <pre> * 返回值有下述几种模式: * MODE_NORMAL( 普通 ) * MODE_RINGTONE( 铃声 ) * MODE_IN_CALL( 打电话 ) * MODE_IN_COMMUNICATION( 通话 ) * </pre> * @return 当前的音频模式 */ public static int getMode() { AudioManager audioManager = AppUtils.getAudioManager(); if (audioManager != null) { try { return audioManager.getMode(); } catch (Exception e) { LogPrintUtils.eTag(TAG, e, "getMode"); } } return AudioManager.MODE_NORMAL; }
Example 14
Source File: AudioRecorder.java From zom-android-matrix with Apache License 2.0 | 5 votes |
public void startAudioRecording() { AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); if (am.getMode() == AudioManager.MODE_NORMAL) { mediaRecorder = new MediaRecorder(); String fileName = UUID.randomUUID().toString().substring(0, 8) + ".m4a"; outputFilePath = new File(context.getFilesDir(), fileName); mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); //maybe we can modify these in the future, or allow people to tweak them mediaRecorder.setAudioChannels(1); mediaRecorder.setAudioEncodingBitRate(22050); mediaRecorder.setAudioSamplingRate(64000); mediaRecorder.setOutputFile(outputFilePath.getAbsolutePath()); try { isAudioRecording = true; mediaRecorder.prepare(); mediaRecorder.start(); if (getVisualizerView() != null) { startLevelListener(); } } catch (Exception e) { Log.e(LOG_TAG, "couldn't start audio", e); } } }
Example 15
Source File: CustomAudioDevice.java From opentok-android-sdk-samples with MIT License | 4 votes |
void acquireMode(AudioManager audioManager) { if (0 == naquire++) { oldMode = audioManager.getMode(); audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); } }
Example 16
Source File: Utils.java From ForceDoze with GNU General Public License v3.0 | 4 votes |
public static boolean isUserInCommunicationCall(Context context) { AudioManager manager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); return manager.getMode() == AudioManager.MODE_IN_CALL || manager.getMode() == AudioManager.MODE_IN_COMMUNICATION; }
Example 17
Source File: AudioPlayerHandler.java From sctalk with Apache License 2.0 | 4 votes |
/**messagePop调用*/ public int getAudioMode(Context ctx) { AudioManager audioManager = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE); return audioManager.getMode(); }
Example 18
Source File: CallActivity.java From sealrtc-android with MIT License | 4 votes |
@Override public void onNotifyHeadsetState(boolean connected, int type) { try { if (connected) { HeadsetPlugReceiverState = true; if (type == 0) { startBluetoothSco(); } if (null != btnMuteSpeaker) { btnMuteSpeaker.setBackgroundResource(R.drawable.img_capture_gray); btnMuteSpeaker.setSelected(false); btnMuteSpeaker.setEnabled(false); btnMuteSpeaker.setClickable(false); audioManager.onToggleSpeaker(false); } } else { if (type == 1 && BluetoothUtil.hasBluetoothA2dpConnected()) { return; } AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); if (am != null) { if (am.getMode() != AudioManager.MODE_IN_COMMUNICATION) { am.setMode(AudioManager.MODE_IN_COMMUNICATION); } if (type == 0) { am.stopBluetoothSco(); am.setBluetoothScoOn(false); am.setSpeakerphoneOn(!muteSpeaker); } else { RCRTCEngine.getInstance().enableSpeaker(!this.muteSpeaker); } audioManager.onToggleSpeaker(!muteSpeaker); } if (null != btnMuteSpeaker) { btnMuteSpeaker.setBackgroundResource(R.drawable.selector_checkbox_capture); btnMuteSpeaker.setSelected(false); btnMuteSpeaker.setEnabled(true); btnMuteSpeaker.setClickable(true); } } } catch (Exception e) { e.printStackTrace(); } }
Example 19
Source File: BgToSpeech.java From xDrip-Experimental with GNU General Public License v3.0 | 4 votes |
private boolean isOngoingCall(){ AudioManager manager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE); return (manager.getMode()==AudioManager.MODE_IN_CALL); }
Example 20
Source File: ConversationDetailActivity.java From Zom-Android-XMPP with GNU General Public License v3.0 | 4 votes |
public void startAudioRecording () { int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO); if (permissionCheck ==PackageManager.PERMISSION_DENIED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.RECORD_AUDIO)) { // Show an expanation to the user *asynchronously* -- don't block // this thread waiting for the user's response! After the user // sees the explanation, try again to request the permission. Snackbar.make(mConvoView.getHistoryView(), R.string.grant_perms, Snackbar.LENGTH_LONG).show(); } else { // No explanation needed, we can request the permission. ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.RECORD_AUDIO}, MY_PERMISSIONS_REQUEST_AUDIO); // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an // app-defined int constant. The callback method gets the // result of the request. } } else { AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); if (am.getMode() == AudioManager.MODE_NORMAL) { mMediaRecorder = new MediaRecorder(); String fileName = UUID.randomUUID().toString().substring(0, 8) + ".m4a"; mAudioFilePath = new File(getFilesDir(), fileName); mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); //maybe we can modify these in the future, or allow people to tweak them mMediaRecorder.setAudioChannels(1); mMediaRecorder.setAudioEncodingBitRate(22050); mMediaRecorder.setAudioSamplingRate(64000); mMediaRecorder.setOutputFile(mAudioFilePath.getAbsolutePath()); try { mIsAudioRecording = true; mMediaRecorder.prepare(); mMediaRecorder.start(); } catch (Exception e) { Log.e(ImApp.LOG_TAG, "couldn't start audio", e); } } } }