List of usage examples for android.media AudioManager getMode
public int getMode()
From source file:Main.java
public static boolean isOnPause(Context ctx) { AudioManager am = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE); return am.getMode() != AudioManager.MODE_NORMAL; }
From source file:Main.java
/** * Call checker//from ww w .ja v a 2 s .c om * @param context * @return true if a call is going on. */ public static boolean isACallActive(Context context) { AudioManager manager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); if (manager.getMode() == AudioManager.MODE_IN_CALL) { return true; } else { return false; } }
From source file:org.linphone.compatibility.ApiElevenPlus.java
public static void setAudioManagerInCallMode(AudioManager manager) { if (manager.getMode() == AudioManager.MODE_IN_COMMUNICATION) { Log.w("---AudioManager: already in MODE_IN_COMMUNICATION, skipping..."); return;//from w w w. j av a2 s . c o m } Log.d("---AudioManager: set mode to MODE_IN_COMMUNICATION"); manager.setMode(AudioManager.MODE_IN_COMMUNICATION); }
From source file:org.zywx.wbpalmstar.plugin.uexaudio.EUExAudio.java
public static void onActivityDestroy(Context context) { BDebug.i(tag, "onActivityDestroy"); AudioManager audioManager = (AudioManager) context.getApplicationContext() .getSystemService(Context.AUDIO_SERVICE); if (audioManager.getMode() == AudioManager.MODE_IN_COMMUNICATION || audioManager.getMode() == AudioManager.MODE_IN_CALL) { audioManager.setMode(AudioManager.MODE_NORMAL); }/*from w w w. ja va2 s . c o m*/ }
From source file:net.micode.soundrecorder.RecorderService.java
private void localStartRecording(int outputfileformat, String path, boolean highQuality, long maxFileSize) { if (mRecorder == null) { mRemainingTimeCalculator.reset(); if (maxFileSize != -1) { mRemainingTimeCalculator.setFileSizeLimit(new File(path), maxFileSize); }//from w ww. ja v a 2 s . c o m mRecorder = new MediaRecorder(); mRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); if (outputfileformat == MediaRecorder.OutputFormat.THREE_GPP) { mRemainingTimeCalculator.setBitRate(SoundRecorder.BITRATE_3GPP); // mRecorder.setAudioChannels(1); mRecorder.setAudioSamplingRate(mAudioSampleRate); mRecorder.setAudioEncodingBitRate(SoundRecorder.BITRATE_3GPP); mRecorder.setOutputFormat(outputfileformat); mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); } else if (outputfileformat == MediaRecorder.OutputFormat.AMR_NB) { mRemainingTimeCalculator.setBitRate(SoundRecorder.BITRATE_AMR); mRecorder.setAudioSamplingRate(highQuality ? 16000 : 8000); mRecorder.setOutputFormat(outputfileformat); mRecorder.setAudioEncoder( highQuality ? MediaRecorder.AudioEncoder.AMR_WB : MediaRecorder.AudioEncoder.AMR_NB); } else { mRemainingTimeCalculator.setBitRate(SoundRecorder.BITRATE_MP3); // mRecorder.setAudioChannels(1); mRecorder.setAudioSamplingRate(mAudioSampleRate); mRecorder.setAudioEncodingBitRate(SoundRecorder.BITRATE_MP3); mRecorder.setOutputFormat(outputfileformat); mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); } mRecorder.setOutputFile(path); mRecorder.setOnErrorListener(this); // Handle IOException try { mRecorder.prepare(); } catch (IOException exception) { sendErrorBroadcast(Recorder.INTERNAL_ERROR); mRecorder.reset(); mRecorder.release(); mRecorder = null; return; } // Handle RuntimeException if the recording couldn't start try { mRecorder.start(); } catch (RuntimeException exception) { AudioManager audioMngr = (AudioManager) getSystemService(Context.AUDIO_SERVICE); boolean isInCall = (audioMngr.getMode() == AudioManager.MODE_IN_CALL); if (isInCall) { sendErrorBroadcast(Recorder.IN_CALL_RECORD_ERROR); } else { sendErrorBroadcast(Recorder.INTERNAL_ERROR); } mRecorder.reset(); mRecorder.release(); mRecorder = null; return; } mFilePath = path; mStartTime = System.currentTimeMillis(); mWakeLock.acquire(); mNeedUpdateRemainingTime = false; sendStateBroadcast(); showRecordingNotification(); NotificationManager nMgr = (NotificationManager) getApplicationContext() .getSystemService(NOTIFICATION_SERVICE); nMgr.cancel(notifyID); } }
From source file:com.royer.bangstopwatch.app.StopwatchFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); Log.d(TAG, "Enter onActivityCreated..."); InitTimeDisplayView();//from w w w. j av a2 s .c o m mLapList = (ListView) getView().findViewById(R.id.listLap); this.registerForContextMenu(mLapList); btnStart = (Button) getView().findViewById(R.id.btnStart); btnStart.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (state == STATE_NONE) { // detect does device support record ? if (AudioRecord.getMinBufferSize(44100, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT) < 0) { Context context = getActivity().getApplicationContext(); Toast toast = Toast.makeText(context, R.string.strNoRecorder, 5); toast.show(); return; } AudioManager audiomanager = (AudioManager) getActivity() .getSystemService(Context.AUDIO_SERVICE); Log.d(TAG, "AudioMode = " + audiomanager.getMode()); if (audiomanager.getMode() != AudioManager.MODE_NORMAL) { Context context = getActivity().getApplicationContext(); Toast toast = Toast.makeText(context, R.string.strInCalling, 5); toast.show(); return; } state = STATE_COUNTDOWN; DialogFragment newFragment = CountdownDialog.NewInstance(5, getTag()); newFragment.show(getFragmentManager(), "countdownDialog"); } else { changeState(); state = STATE_NONE; updateRealElapseTime(); printTime(); // unBind Recordservice if (mBound) { mService.stopRecord(); mService.unsetBang(); getActivity().unbindService(mConnection); getActivity().stopService(new Intent(getActivity(), RecordService.class)); mBound = false; } } ((MainActivity) getActivity()).EnableTab(1, state == STATE_NONE); } }); if (savedInstanceState != null) { Log.d(TAG, "savedInstanceState " + savedInstanceState.toString()); _timekeeper = savedInstanceState.getParcelable(STATE_TIMEKEEPER); mLapManager = savedInstanceState.getParcelable(STATE_LAPS); state = savedInstanceState.getInt(STATE_STATE); mBound = savedInstanceState.getBoolean(STATE_BOUNDING); ((MainActivity) getActivity()).EnableTab(1, state == STATE_NONE); } else { Log.d(TAG, "savedInstanceState == NULL"); if (_timekeeper == null) _timekeeper = new Timekeeper(); if (mLapManager == null) mLapManager = new LapManager(); } InitLapList(); printTime(); updateState(); Log.d(TAG, "Leave OnActivityCreated..."); }
From source file:fr.inria.ucn.collectors.SysStateCollector.java
@SuppressWarnings("deprecation") private JSONObject getAudioState(Context c) throws JSONException { AudioManager am = (AudioManager) c.getSystemService(Context.AUDIO_SERVICE); JSONObject data = new JSONObject(); data.put("is_bluetooth_a2dp_on", am.isBluetoothA2dpOn()); data.put("is_microphone_mute", am.isMicrophoneMute()); data.put("is_music_active", am.isMusicActive()); data.put("is_speaker_phone_on", am.isSpeakerphoneOn()); data.put("is_wired_headset_on", am.isWiredHeadsetOn()); switch (am.getMode()) { case AudioManager.MODE_IN_CALL: data.put("mode", "in_call"); break;/*ww w.j ava 2 s.c om*/ case AudioManager.MODE_IN_COMMUNICATION: data.put("mode", "in_comm"); break; case AudioManager.MODE_NORMAL: data.put("mode", "normal"); break; case AudioManager.MODE_RINGTONE: data.put("mode", "ringtone"); break; case AudioManager.MODE_INVALID: default: data.put("mode", "invalid"); break; } switch (am.getRingerMode()) { case AudioManager.RINGER_MODE_VIBRATE: data.put("ringer_mode", "vibrate"); break; case AudioManager.RINGER_MODE_SILENT: data.put("ringer_mode", "silent"); break; case AudioManager.RINGER_MODE_NORMAL: data.put("ringer_mode", "normal"); break; default: data.put("ringer_mode", "invalid"); break; } return data; }
From source file:com.sean.takeastand.alarmprocess.AlarmService.java
private void updateNotification() { /*if (!bRepeatingAlarmStepCheck) { mNotifTimePassed++;/*from w w w . j a v a 2s . com*/ } Log.i(TAG, "time since first notification: " + mNotifTimePassed + setMinutes(mNotifTimePassed));*/ NotificationManager notificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent[] pendingIntents = makeNotificationIntents(); RemoteViews rvRibbon = new RemoteViews(getPackageName(), R.layout.stand_notification); rvRibbon.setOnClickPendingIntent(R.id.btnStood, pendingIntents[1]); rvRibbon.setTextViewText(R.id.notificationTimeStamp, notificationClockTime); /*rvRibbon.setTextViewText(R.id.stand_up_minutes, mNotifTimePassed + setMinutes(mNotifTimePassed)); rvRibbon.setTextViewText(R.id.topTextView, getString(R.string.stand_up_time_up));*/ NotificationCompat.Builder alarmNotificationBuilder = new NotificationCompat.Builder(this); alarmNotificationBuilder.setContent(rvRibbon); alarmNotificationBuilder.setContentIntent(pendingIntents[0]).setAutoCancel(false) .setTicker(getString(R.string.stand_up_time_low)).setSmallIcon(R.drawable.ic_notification_small) .setContentTitle("Take A Stand ") //.setContentText("Mark Stood\n" + mNotifTimePassed + setMinutes(mNotifTimePassed)) .extend(new NotificationCompat.WearableExtender().addAction( new NotificationCompat.Action.Builder(R.drawable.ic_action_done, "Stood", pendingIntents[1]) .build()) .setContentAction(0).setHintHideIcon(true) // .setBackground(BitmapFactory.decodeResource(getResources(), R.drawable.alarm_schedule_passed)) ); boolean[] alertType; if (mCurrentAlarmSchedule != null) { alertType = mCurrentAlarmSchedule.getAlertType(); } else { alertType = Utils.getDefaultAlertType(this); } if ((alertType[0])) { alarmNotificationBuilder.setLights(238154000, 1000, 4000); } if (Utils.getRepeatAlerts(this)) { if (alertType[1]) { boolean bUseLastStepCounters = false; if (!bRepeatingAlarmStepCheck) { bRepeatingAlarmStepCheck = true; bUseLastStepCounters = UseLastStepCounters(null); } if (!bUseLastStepCounters) { bRepeatingAlarmStepCheck = false; alarmNotificationBuilder.setVibrate(mVibrationPattern); AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); if (audioManager.getMode() == AudioManager.RINGER_MODE_SILENT && Utils.getVibrateOverride(this)) { Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(mVibrationPattern, -1); } } } if (alertType[2]) { Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); alarmNotificationBuilder.setSound(soundUri); } } Notification alarmNotification = alarmNotificationBuilder.build(); notificationManager.notify(R.integer.AlarmNotificationID, alarmNotification); }
From source file:com.sean.takeastand.alarmprocess.AlarmService.java
private void sendNotification() { NotificationManager notificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent[] pendingIntents = makeNotificationIntents(); RemoteViews rvRibbon = new RemoteViews(getPackageName(), R.layout.stand_notification); rvRibbon.setOnClickPendingIntent(R.id.btnStood, pendingIntents[1]); notificationClockTime = Utils.getFormattedCalendarTime(Calendar.getInstance(), this); rvRibbon.setTextViewText(R.id.notificationTimeStamp, notificationClockTime); NotificationCompat.Builder alarmNotificationBuilder = new NotificationCompat.Builder(this); alarmNotificationBuilder.setContent(rvRibbon).setContentIntent(pendingIntents[0]).setAutoCancel(false) .setTicker(getString(R.string.stand_up_time_low)).setSmallIcon(R.drawable.ic_notification_small) .setContentTitle("Take A Stand ").setContentText( "Mark Stood") .extend(new NotificationCompat.WearableExtender().addAction( new NotificationCompat.Action.Builder(R.drawable.ic_action_done, "Stood", pendingIntents[2]) .build())// ww w .j ava 2s.com .setContentAction(0).setHintHideIcon(true) // .setBackground(BitmapFactory.decodeResource(getResources(), R.drawable.alarm_schedule_passed)) ); //Purpose of below is to figure out what type of user alert to give with the notification //If scheduled, check settings for that schedule //If unscheduled, check user defaults if (mCurrentAlarmSchedule != null) { boolean[] alertType = mCurrentAlarmSchedule.getAlertType(); if ((alertType[0])) { alarmNotificationBuilder.setLights(238154000, 1000, 4000); } if (alertType[1]) { alarmNotificationBuilder.setVibrate(mVibrationPattern); AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); if (audioManager.getMode() == AudioManager.RINGER_MODE_SILENT && Utils.getVibrateOverride(this)) { Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(mVibrationPattern, -1); } } if (alertType[2]) { Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); alarmNotificationBuilder.setSound(soundUri); } } else { boolean[] alertType = Utils.getDefaultAlertType(this); if ((alertType[0])) { alarmNotificationBuilder.setLights(238154000, 1000, 4000); } if (alertType[1]) { alarmNotificationBuilder.setVibrate(mVibrationPattern); AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); if (audioManager.getMode() == AudioManager.RINGER_MODE_SILENT && Utils.getVibrateOverride(this)) { Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(mVibrationPattern, -1); } } if (alertType[2]) { Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); alarmNotificationBuilder.setSound(soundUri); } } Notification alarmNotification = alarmNotificationBuilder.build(); notificationManager.notify(R.integer.AlarmNotificationID, alarmNotification); if (getSharedPreferences(Constants.USER_SHARED_PREFERENCES, 0).getBoolean(Constants.STANDDTECTORTM_ENABLED, false)) { Intent standSensorIntent = new Intent(this, StandDtectorTM.class); standSensorIntent.setAction(com.heckbot.standdtector.Constants.STANDDTECTOR_START); standSensorIntent.putExtra("MILLISECONDS", (long) 60000); standSensorIntent.putExtra("pendingIntent", pendingIntents[1]); startService(standSensorIntent); } }
From source file:im.vector.activity.CallViewActivity.java
@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(""); }//w w w. jav a 2 s. c om } 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); }