List of usage examples for android.media AudioManager STREAM_RING
int STREAM_RING
To view the source code for android.media AudioManager STREAM_RING.
Click Source Link
From source file:org.wso2.mdm.agent.services.Operation.java
/** * Mute the device.//from w w w . j a v a 2 s . c o m * @param code - Operation code. * @param requestMode - Request mode(Normal mode or policy bundle mode). */ private void muteDevice(String code) { resultBuilder.build(code); AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); audioManager.setStreamVolume(AudioManager.STREAM_RING, DEFAULT_VOLUME, DEFAULT_FLAG); }
From source file:org.linphone.LinphoneService.java
private synchronized void startRinging() { try {/*from w w w . ja v a 2 s . co m*/ if (mAudioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER) && mVibrator != null) { long[] patern = { 0, 1000, 1000 }; mVibrator.vibrate(patern, 1); } if (mRingerPlayer == null) { mRingerPlayer = new MediaPlayer(); mRingerPlayer.setAudioStreamType(AudioManager.STREAM_RING); mRingerPlayer.setDataSource(getApplicationContext(), RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE)); mRingerPlayer.prepare(); mRingerPlayer.setLooping(true); mRingerPlayer.start(); } else { Log.w(LinphoneService.TAG, "already ringing"); } } catch (Exception e) { Log.e(LinphoneService.TAG, "cannot handle incoming call", e); } }
From source file:com.ferdi2005.secondgram.voip.VoIPService.java
private void startRinging() { FileLog.d("starting ringing for call " + call.id); dispatchStateChanged(STATE_WAITING_INCOMING); //ringtone=RingtoneManager.getRingtone(this, Settings.System.DEFAULT_RINGTONE_URI); //ringtone.play(); SharedPreferences prefs = getSharedPreferences("Notifications", MODE_PRIVATE); ringtonePlayer = new MediaPlayer(); ringtonePlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override// w w w .j a va2s . co m public void onPrepared(MediaPlayer mediaPlayer) { ringtonePlayer.start(); } }); ringtonePlayer.setLooping(true); ringtonePlayer.setAudioStreamType(AudioManager.STREAM_RING); try { String notificationUri; if (prefs.getBoolean("custom_" + user.id, false)) notificationUri = prefs.getString("ringtone_path_" + user.id, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE).toString()); else notificationUri = prefs.getString("CallsRingtonePath", RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE).toString()); ringtonePlayer.setDataSource(this, Uri.parse(notificationUri)); ringtonePlayer.prepareAsync(); } catch (Exception e) { FileLog.e(e); if (ringtonePlayer != null) { ringtonePlayer.release(); ringtonePlayer = null; } } AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE); int vibrate; if (prefs.getBoolean("custom_" + user.id, false)) vibrate = prefs.getInt("calls_vibrate_" + user.id, 0); else vibrate = prefs.getInt("vibrate_calls", 0); if ((vibrate != 2 && vibrate != 4 && (am.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE || am.getRingerMode() == AudioManager.RINGER_MODE_NORMAL)) || (vibrate == 4 && am.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE)) { vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); long duration = 700; if (vibrate == 1) duration /= 2; else if (vibrate == 3) duration *= 2; vibrator.vibrate(new long[] { 0, duration, 500 }, 0); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !((KeyguardManager) getSystemService(KEYGUARD_SERVICE)).inKeyguardRestrictedInputMode() && NotificationManagerCompat.from(this).areNotificationsEnabled()) { showIncomingNotification(); FileLog.d("Showing incoming call notification"); } else { FileLog.d("Starting incall activity for incoming call"); try { PendingIntent.getActivity(VoIPService.this, 12345, new Intent(VoIPService.this, VoIPActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 0) .send(); } catch (Exception x) { FileLog.e("Error starting incall activity", x); } } }
From source file:com.wso2.mobile.mdm.services.PolicyTester.java
private boolean isMuted() { AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); if (audioManager.getStreamVolume(AudioManager.STREAM_RING) != 0) { return false; } else {// ww w . j a va 2 s .com return true; } }
From source file:com.example.mydemos.view.RingtonePickerActivity.java
@Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) { Log.e("lys", "onItemClick position ==" + position + "id" + id); if (id == -1) { if (mHasSilentItem) { if ((mHasDefaultItem && (position == 1)) || !mHasDefaultItem) { Log.e("lys", "onItemClick silentItemChecked == true"); //toneCur.moveToPosition(position); mSelectedId = SILENT_ID; mSelectedUri = null;/*from w w w.j a v a2 s . com*/ silentItemChecked = true; defaultItemChecked = false; stopMediaPlayer(); listView.invalidateViews(); return; } else if (mHasDefaultItem && (position == 0)) { Log.e("lys", "onItemClick defaultItemChecked == true"); //toneCur.moveToPosition(position); mSelectedId = DEFAULT_ID; mSelectedUri = mUriForDefaultItem; defaultItemChecked = true; silentItemChecked = false; } } else { if (mHasDefaultItem) { Log.e("lys", "onItemClick defaultItemChecked == true"); //toneCur.moveToPosition(position); mSelectedId = DEFAULT_ID; mSelectedUri = mUriForDefaultItem; defaultItemChecked = true; silentItemChecked = false; } } } else { if (mHasSilentItem) { silentItemChecked = false; position--; } if (mHasDefaultItem) { defaultItemChecked = false; position--; } } if (id != -1) { toneCur.moveToPosition(position); Log.e("lys", "onItemClick position == " + position + "id ==" + id); long newId = toneCur.getLong(toneCur.getColumnIndex(MediaStore.Audio.Media._ID)); mSelectedId = newId; Log.e("lys", " onItemClick mSelectedId==" + mSelectedId); //wuqingliang modify begin20130307 if (tabName == SYSTEM_TONE) { BaseUri = MediaStore.Audio.Media.INTERNAL_CONTENT_URI; Log.e("lys", "BaseUri = MediaStore.Audio.Media.INTERNAL_CONTENT_URI;111111"); } else { BaseUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; Log.e("lys", "BaseUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;1111111"); } //wuqingliang modify end mSelectedUri = ContentUris.withAppendedId(BaseUri, newId); } listView.invalidateViews(); audioManager.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT); stopMediaPlayer(); mMediaPlayer = new MediaPlayer(); try { if (toneType == ALARM_TYPE) mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM); else mMediaPlayer.setAudioStreamType(AudioManager.STREAM_RING); mMediaPlayer.setDataSource(RingtonePickerActivity.this, mSelectedUri); mMediaPlayer.prepare(); mMediaPlayer.start(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:net.czlee.debatekeeper.DebatingActivity.java
/** * Gets the preferences from the shared preferences file and applies them. *///from w w w . ja va2 s . c om private void applyPreferences() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); boolean silentMode, vibrateMode, overtimeBellsEnabled; boolean poiBuzzerEnabled, poiVibrateEnabled, prepTimerEnabled; int firstOvertimeBell, overtimeBellPeriod; String userCountDirectionValue, userPrepTimeCountDirectionValue, poiFlashScreenModeValue, backgroundColourAreaValue; FlashScreenMode flashScreenMode, poiFlashScreenMode; Resources res = getResources(); final String TAG = "applyPreferences"; try { // The boolean preferences silentMode = prefs.getBoolean(res.getString(R.string.pref_silentMode_key), res.getBoolean(R.bool.prefDefault_silentMode)); vibrateMode = prefs.getBoolean(res.getString(R.string.pref_vibrateMode_key), res.getBoolean(R.bool.prefDefault_vibrateMode)); overtimeBellsEnabled = prefs.getBoolean(res.getString(R.string.pref_overtimeBellsEnable_key), res.getBoolean(R.bool.prefDefault_overtimeBellsEnable)); mSpeechKeepScreenOn = prefs.getBoolean(res.getString(R.string.pref_keepScreenOn_key), res.getBoolean(R.bool.prefDefault_keepScreenOn)); mPrepTimeKeepScreenOn = prefs.getBoolean(res.getString(R.string.pref_prepTimer_keepScreenOn_key), res.getBoolean(R.bool.prefDefault_prepTimer_keepScreenOn)); mPoiTimerEnabled = prefs.getBoolean(res.getString(R.string.pref_poiTimer_enable_key), res.getBoolean(R.bool.prefDefault_poiTimer_enable)); poiBuzzerEnabled = prefs.getBoolean(res.getString(R.string.pref_poiTimer_buzzerEnable_key), res.getBoolean(R.bool.prefDefault_poiTimer_buzzerEnable)); poiVibrateEnabled = prefs.getBoolean(res.getString(R.string.pref_poiTimer_vibrateEnable_key), res.getBoolean(R.bool.prefDefault_poiTimer_vibrateEnable)); prepTimerEnabled = prefs.getBoolean(res.getString(R.string.pref_prepTimer_enable_key), res.getBoolean(R.bool.prefDefault_prepTimer_enable)); // Overtime bell integers if (overtimeBellsEnabled) { firstOvertimeBell = prefs.getInt(res.getString(R.string.pref_firstOvertimeBell_key), res.getInteger(R.integer.prefDefault_firstOvertimeBell)); overtimeBellPeriod = prefs.getInt(res.getString(R.string.pref_overtimeBellPeriod_key), res.getInteger(R.integer.prefDefault_overtimeBellPeriod)); } else { firstOvertimeBell = 0; overtimeBellPeriod = 0; } // List preference: POI flash screen mode poiFlashScreenModeValue = prefs.getString(res.getString(R.string.pref_poiTimer_flashScreenMode_key), res.getString(R.string.prefDefault_poiTimer_flashScreenMode)); poiFlashScreenMode = FlashScreenMode.toEnum(poiFlashScreenModeValue); // List preference: Count direction // - Backwards compatibility measure // This changed in version 0.9, to remove the generallyUp and generallyDown options. // Therefore, if we find either of those, we need to replace it with alwaysUp or // alwaysDown, respectively. userCountDirectionValue = prefs.getString(res.getString(R.string.pref_countDirection_key), res.getString(R.string.prefDefault_countDirection)); if (userCountDirectionValue.equals("generallyUp") || userCountDirectionValue.equals("generallyDown")) { // Replace the preference with alwaysUp or alwaysDown, respectively. SharedPreferences.Editor editor = prefs.edit(); String newValue = (userCountDirectionValue.equals("generallyUp")) ? "alwaysUp" : "alwaysDown"; editor.putString(res.getString(R.string.pref_countDirection_key), newValue); editor.apply(); Log.i(TAG, "countDirection: replaced " + userCountDirectionValue + " with " + newValue); userCountDirectionValue = newValue; } mCountDirection = CountDirection.toEnum(userCountDirectionValue); // List preference: Count direction for prep time userPrepTimeCountDirectionValue = prefs.getString( res.getString(R.string.pref_prepTimer_countDirection_key), res.getString(R.string.prefDefault_prepTimer_countDirection)); mPrepTimeCountDirection = CountDirection.toEnum(userPrepTimeCountDirectionValue); // List preference: Background colour area BackgroundColourArea oldBackgroundColourArea = mBackgroundColourArea; backgroundColourAreaValue = prefs.getString(res.getString(R.string.pref_backgroundColourArea_key), res.getString(R.string.prefDefault_backgroundColourArea)); mBackgroundColourArea = BackgroundColourArea.toEnum(backgroundColourAreaValue); if (oldBackgroundColourArea != mBackgroundColourArea) { Log.v(TAG, "background colour preference changed - refreshing"); resetBackgroundColoursToTransparent(); ((DebateTimerDisplayPagerAdapter) mViewPager.getAdapter()).refreshBackgroundColours(); } // List preference: Flash screen mode // - Backwards compatibility measure // This changed from a boolean to a list preference in version 0.6, so there is // backwards compatibility to take care of. Backwards compatibility applies if // (a) the list preference is NOT present AND (b) the boolean preference IS present. // In this case, retrieve the boolean preference, delete it and write the corresponding // list preference. In all other cases, just take the list preference (using the // normal default mechanism if it isn't present, i.e. neither are present). if (!prefs.contains(res.getString(R.string.pref_flashScreenMode_key)) && prefs.contains(res.getString(R.string.pref_flashScreenBool_key))) { // Boolean preference. // First, get the string and convert it to an enum. boolean flashScreenModeBool = prefs.getBoolean(res.getString(R.string.pref_flashScreenBool_key), false); flashScreenMode = (flashScreenModeBool) ? FlashScreenMode.SOLID_FLASH : FlashScreenMode.OFF; // Then, convert that enum to the list preference value (a string) and write that // back to the preferences. Also, remove the old boolean preference. String flashStringModePrefValue = flashScreenMode.toPrefValue(); SharedPreferences.Editor editor = prefs.edit(); editor.putString(res.getString(R.string.pref_flashScreenMode_key), flashStringModePrefValue); editor.remove(res.getString(R.string.pref_flashScreenBool_key)); editor.apply(); Log.i(TAG, "flashScreenMode: replaced boolean preference with list preference: " + flashStringModePrefValue); } else { // List preference. // Get the string and convert it to an enum. String flashScreenModeValue; flashScreenModeValue = prefs.getString(res.getString(R.string.pref_flashScreenMode_key), res.getString(R.string.prefDefault_flashScreenMode)); flashScreenMode = FlashScreenMode.toEnum(flashScreenModeValue); } } catch (ClassCastException e) { Log.e(TAG, "caught ClassCastException!"); return; } if (mDebateManager != null) { mDebateManager.setOvertimeBells(firstOvertimeBell, overtimeBellPeriod); mDebateManager.setPrepTimeEnabled(prepTimerEnabled); applyPrepTimeBells(); // This is necessary if the debate structure has changed, i.e. if prep time has been // enabled or disabled. mViewPager.getAdapter().notifyDataSetChanged(); } else { Log.v(TAG, "Couldn't restore overtime bells, mDebateManager doesn't yet exist"); } if (mBinder != null) { AlertManager am = mBinder.getAlertManager(); // Volume control stream is linked to silent mode am.setSilentMode(silentMode); setVolumeControlStream((silentMode) ? AudioManager.STREAM_RING : AudioManager.STREAM_MUSIC); am.setVibrateMode(vibrateMode); am.setFlashScreenMode(flashScreenMode); am.setPoiBuzzerEnabled(poiBuzzerEnabled); am.setPoiVibrateEnabled(poiVibrateEnabled); am.setPoiFlashScreenMode(poiFlashScreenMode); this.updateKeepScreenOn(); Log.v(TAG, "successfully applied"); } else { Log.v(TAG, "Couldn't restore AlertManager preferences; mBinder doesn't yet exist"); } }
From source file:com.wso2.mobile.mdm.services.Operation.java
/** * Mute the device//from w w w . j a v a 2 s .co m */ private void muteDevice() { Log.v("MUTING THE DEVICE : ", "MUTING"); AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); Log.v("VOLUME : ", "" + audioManager.getStreamVolume(AudioManager.STREAM_RING)); audioManager.setStreamVolume(AudioManager.STREAM_RING, 0, 0); Log.v("VOLUME AFTER: ", "" + audioManager.getStreamVolume(AudioManager.STREAM_RING)); }
From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java
protected void muteAllSounds() { ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)) .setStreamMute(AudioManager.STREAM_ALARM, true); ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)) .setStreamMute(AudioManager.STREAM_DTMF, true); ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)) .setStreamMute(AudioManager.STREAM_MUSIC, true); ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)) .setStreamMute(AudioManager.STREAM_NOTIFICATION, true); ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)) .setStreamMute(AudioManager.STREAM_RING, true); ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)) .setStreamMute(AudioManager.STREAM_SYSTEM, true); ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)) .setStreamMute(AudioManager.STREAM_VOICE_CALL, true); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_ALARM, 0, 0); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_DTMF, 0, 0); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_RING, 0, 0); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_SYSTEM, 0, 0); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_VOICE_CALL, 0, 0); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).adjustStreamVolume(AudioManager.STREAM_ALARM, AudioManager.ADJUST_MUTE, 0); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).adjustStreamVolume(AudioManager.STREAM_DTMF, AudioManager.ADJUST_MUTE, 0); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_MUTE, 0); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).adjustStreamVolume(AudioManager.STREAM_RING, AudioManager.ADJUST_MUTE, 0); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).adjustStreamVolume(AudioManager.STREAM_SYSTEM, AudioManager.ADJUST_MUTE, 0); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).adjustStreamVolume(AudioManager.STREAM_VOICE_CALL, AudioManager.ADJUST_MUTE, 0); }
From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java
protected void unmuteAllSounds() { ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)) .setStreamMute(AudioManager.STREAM_ALARM, false); ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)) .setStreamMute(AudioManager.STREAM_DTMF, false); ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)) .setStreamMute(AudioManager.STREAM_MUSIC, false); ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)) .setStreamMute(AudioManager.STREAM_NOTIFICATION, false); ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)) .setStreamMute(AudioManager.STREAM_RING, false); ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)) .setStreamMute(AudioManager.STREAM_SYSTEM, false); ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)) .setStreamMute(AudioManager.STREAM_VOICE_CALL, false); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_ALARM, 0, 0); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_DTMF, 0, 0); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_RING, 0, 0); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_SYSTEM, 0, 0); }