Java Code Examples for android.media.AudioManager#RINGER_MODE_SILENT
The following examples show how to use
android.media.AudioManager#RINGER_MODE_SILENT .
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: RingerModeAndScreenMonitor.java From talkback with Apache License 2.0 | 6 votes |
/** * Appends the ringer state announcement to a {@link StringBuilder}. * * @param builder The string to append to. */ private void appendRingerStateAnnouncement(SpannableStringBuilder builder) { if (telephonyManager == null) { return; } final String announcement; switch (ringerMode) { case AudioManager.RINGER_MODE_SILENT: announcement = service.getString(R.string.value_ringer_silent); break; case AudioManager.RINGER_MODE_VIBRATE: announcement = service.getString(R.string.value_ringer_vibrate); break; case AudioManager.RINGER_MODE_NORMAL: return; default: LogUtils.e(TAG, "Unknown ringer mode: %d", ringerMode); return; } StringBuilderUtils.appendWithSeparator(builder, announcement); }
Example 2
Source File: AppUtils.java From BigApp_Discuz_Android with Apache License 2.0 | 6 votes |
public static boolean autoChangeAlarm(Context context) { try { AudioManager audioManager = (AudioManager) context .getApplicationContext().getSystemService( Context.AUDIO_SERVICE); // audioManager.setRingerMode(RINGER_MODE_NORMAL或者RINGER_MODE_SILENT或者RINGER_MODE_VIBRATE); // android.media.AudioManager.RINGER_MODE_NORMAL = 2; if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) { audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); } else if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) { audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); } return true; } catch (Exception e) { return false; } }
Example 3
Source File: KcaAlarmService.java From kcanotify with GNU General Public License v3.0 | 5 votes |
private NotificationCompat.Builder setSoundSetting(NotificationCompat.Builder builder) { String soundKind = getStringPreferences(getApplicationContext(), PREF_KCA_NOTI_SOUND_KIND); if (soundKind.equals(getString(R.string.sound_kind_value_normal)) || soundKind.equals(getString(R.string.sound_kind_value_mixed))) { if (mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) { if (soundKind.equals(getString(R.string.sound_kind_value_mixed))) { builder.setDefaults(Notification.DEFAULT_VIBRATE); } Uri content_uri = getContentUri(getApplicationContext(), Uri.parse(getStringPreferences(getApplicationContext(), PREF_KCA_NOTI_RINGTONE))); builder.setSound(content_uri); } else if (mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) { builder.setDefaults(Notification.DEFAULT_VIBRATE); } else { builder.setDefaults(0); } } if (soundKind.equals(getString(R.string.sound_kind_value_vibrate))) { if (mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_SILENT) { builder.setDefaults(Notification.DEFAULT_VIBRATE); } else { builder.setDefaults(0); } } if (soundKind.equals(getString(R.string.sound_kind_value_mute))) { builder.setDefaults(0); } return builder; }
Example 4
Source File: VibratorService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private boolean shouldVibrateForRingtone() { AudioManager audioManager = mContext.getSystemService(AudioManager.class); int ringerMode = audioManager.getRingerModeInternal(); // "Also vibrate for calls" Setting in Sound if (Settings.System.getInt( mContext.getContentResolver(), Settings.System.VIBRATE_WHEN_RINGING, 0) != 0) { return ringerMode != AudioManager.RINGER_MODE_SILENT; } else { return ringerMode == AudioManager.RINGER_MODE_VIBRATE; } }
Example 5
Source File: ZenLog.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private static String ringerModeToString(int ringerMode) { switch (ringerMode) { case AudioManager.RINGER_MODE_SILENT: return "silent"; case AudioManager.RINGER_MODE_VIBRATE: return "vibrate"; case AudioManager.RINGER_MODE_NORMAL: return "normal"; default: return "unknown"; } }
Example 6
Source File: ZenModeHelper.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@VisibleForTesting protected void applyZenToRingerMode() { if (mAudioManager == null) return; // force the ringer mode into compliance final int ringerModeInternal = mAudioManager.getRingerModeInternal(); int newRingerModeInternal = ringerModeInternal; switch (mZenMode) { case Global.ZEN_MODE_NO_INTERRUPTIONS: case Global.ZEN_MODE_ALARMS: if (ringerModeInternal != AudioManager.RINGER_MODE_SILENT) { setPreviousRingerModeSetting(ringerModeInternal); newRingerModeInternal = AudioManager.RINGER_MODE_SILENT; } break; case Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS: // do not apply zen to ringer, streams zen muted in AudioService break; case Global.ZEN_MODE_OFF: if (ringerModeInternal == AudioManager.RINGER_MODE_SILENT) { newRingerModeInternal = getPreviousRingerModeSetting(); setPreviousRingerModeSetting(null); } break; } if (newRingerModeInternal != -1) { mAudioManager.setRingerModeInternal(newRingerModeInternal, TAG); } }
Example 7
Source File: ParanoidVolumePanel.java From Noyze with Apache License 2.0 | 5 votes |
protected int[] _getStreamIcons(StreamControl sc) { int[] icons = getStreamIcons(sc); if (sc.streamType == AudioManager.STREAM_NOTIFICATION || sc.streamType == AudioManager.STREAM_RING) { switch (mRingerMode) { case AudioManager.RINGER_MODE_VIBRATE: icons[1] = getVibrateIcon(); break; case AudioManager.RINGER_MODE_SILENT: icons[1] = getSilentIcon(); break; } } return icons; }
Example 8
Source File: HeadsUpVolumePanel.java From Noyze with Apache License 2.0 | 5 votes |
@Override public void onStreamVolumeChange(int streamType, int volume, int max) { StreamResources resources = StreamResources.resourceForStreamType(streamType); LOGD(TAG, "onStreamVolumeChange(" + VolumeManager.getStreamName(streamType) + ", " + volume + ", " + max + ")"); resources.setVolume(volume); if (!hasAlbumArt) updateIcon(resources); if (!hasDuration) { seekBar.setMax(max); seekBar.setProgress(volume); } LayerDrawable layer = (LayerDrawable) seekBar.getProgressDrawable(); layer.findDrawableByLayerId(android.R.id.progress).mutate().setColorFilter(color, PorterDuff.Mode.MULTIPLY); seekBar.setTag(resources); if (!mMusicActive) { int descRes = resources.getDescRes(); // Display silent/ vibrate based on the ringer setting. if (resources.getVolume() <= 0 && (resources == StreamResources.RingerStream || resources == StreamResources.NotificationStream)) { if (mRingerMode == AudioManager.RINGER_MODE_VIBRATE) { descRes = R.string.vibrate_c; } else if (mRingerMode == AudioManager.RINGER_MODE_SILENT) { descRes = R.string.silent_c; } } song.setText(descRes); artist.setText(null); artist.setVisibility(View.GONE); } show(); }
Example 9
Source File: Controls.java From homescreenarcade with GNU General Public License v3.0 | 5 votes |
public void vibrateShort() { if (v == null) return; if (!buttonVibrationEnabled) return; if(((AudioManager)host.getSystemService(Context.AUDIO_SERVICE)).getRingerMode() == AudioManager.RINGER_MODE_SILENT) return; if((host.game.getTime() - shortVibeTime) > (host.getResources().getInteger(R.integer.shortVibeInterval) + vibrationOffset)) { shortVibeTime = host.game.getTime(); v.vibrate(vibrationOffset); } }
Example 10
Source File: Controls.java From homescreenarcade with GNU General Public License v3.0 | 5 votes |
public void vibrateBottom() { if (v == null) return; if (!eventVibrationEnabled) return; if(((AudioManager)host.getSystemService(Context.AUDIO_SERVICE)).getRingerMode() == AudioManager.RINGER_MODE_SILENT) return; v.cancel(); v.vibrate(new long[] {0, 5 + vibrationOffset, 30 + vibrationOffset, 20 + vibrationOffset}, -1); }
Example 11
Source File: RtcActivity.java From imsdk-android with MIT License | 5 votes |
private void playAudio() { switch (audioManager.getRingMode()) { case AudioManager.RINGER_MODE_NORMAL://响铃 case AudioManager.MODE_IN_COMMUNICATION://音频通话 MediaUtils.playRtcSound(RtcActivity.this, R.raw.atom_rtc_video_prompt); if(!isCaller) { audioManager.changeToEarpieceMode(); } else { audioManager.changeToSpeakerMode(); } // MediaUtils.loadRtcSound(RtcActivity.this, R.raw.atom_rtc_video_prompt); // MediaUtils.playRtcTone(RtcActivity.this); break; case AudioManager.RINGER_MODE_SILENT://静音 case AudioManager.RINGER_MODE_VIBRATE://震动 if(!isCaller) { MediaUtils.playRtcSound(RtcActivity.this, R.raw.atom_rtc_video_prompt); audioManager.changeToEarpieceMode(); } else { vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); //按照指定的模式去震动。 // vibrator.vibrate(1000); //数组参数意义:第一个参数为等待指定时间后开始震动,震动时间为第二个参数。后边的参数依次为等待震动和震动的时间 //第二个参数为重复次数,-1为不重复,0为一直震动 vibrator.vibrate( new long[]{1000,1000},0); } break; } }
Example 12
Source File: iOSVolumePanel.java From Noyze with Apache License 2.0 | 5 votes |
@Override public void onStreamVolumeChange(int streamType, int volume, int max) { // Update the icon & progress based on the volume_3 change. StreamResources resources = StreamResources.resourceForStreamType(streamType); resources.setVolume(volume); LOGD(TAG, "onStreamVolumeChange(" + streamType + ", " + volume + ", " + max + ")"); int[] icons = iconForStream(resources); int iconRes = ((resources.getVolume() <= 0) ? icons[1] : icons[0]); toggleSilent((resources.getVolume() <= 0) ? View.VISIBLE : View.GONE); // Animate the speaker icon based on the volume level. if (iconRes == R.drawable.volume_3) { if (volume == 0 && mRingerMode == AudioManager.RINGER_MODE_SILENT) { iconRes = R.drawable.volume_0; } else if (volume <= (max / 3)) { iconRes = R.drawable.volume_1; } else if (volume <= ((2 * max) / 3)) { iconRes = R.drawable.volume_2; } else { iconRes = R.drawable.volume_3; } } icon.setImageResource(iconRes); volumeText.setText(resources.getDescRes()); int largest = mVolumeManager.getLargestMax(); seekBar.setProgress(normalizeVolume(volume, max, largest), largest); show(); }
Example 13
Source File: ParanoidVolumePanel.java From Noyze with Apache License 2.0 | 5 votes |
protected int[] getStreamIcons(StreamControl sc) { if (sc.streamType == AudioManager.STREAM_NOTIFICATION || sc.streamType == AudioManager.STREAM_RING) { switch (mRingerMode) { case AudioManager.RINGER_MODE_VIBRATE: return new int[] { sc.iconRes, getVibrateIcon() }; case AudioManager.RINGER_MODE_SILENT: return new int[] { sc.iconRes, getSilentIcon() }; } } return new int[] { sc.iconRes, sc.iconMuteRes }; // Default icons }
Example 14
Source File: RingerModeOperationData.java From Easer with GNU General Public License v3.0 | 5 votes |
public void parse(@NonNull String data, @NonNull PluginDataFormat format, int version) throws IllegalStorageDataException { switch (format) { default: if (version < C.VERSION_GRANULAR_RINGER_MODE) { // backward compatible // was IntegerOperationData, [0, 2] Integer level = Integer.valueOf(data); switch (level) { case AudioManager.RINGER_MODE_SILENT: if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) ringerMode = RingerMode.silent; else ringerMode = RingerMode.dnd_none; break; case AudioManager.RINGER_MODE_VIBRATE: ringerMode = RingerMode.vibrate; break; case AudioManager.RINGER_MODE_NORMAL: ringerMode = RingerMode.normal; break; default: throw new IllegalStateException("Compatibility for RingerMode shouldn't run out of cases"); } } else { ringerMode = RingerMode.valueOf(data); } } }
Example 15
Source File: DeviceTest.java From unity-ads-android with Apache License 2.0 | 5 votes |
@Test public void testGetRingerMode () { int[] expected = {AudioManager.RINGER_MODE_NORMAL, AudioManager.RINGER_MODE_SILENT, AudioManager.RINGER_MODE_VIBRATE}; int ringerMode = Device.getRingerMode(); boolean found = false; for (int value : expected) { if (value == ringerMode) { found = true; break; } } assertTrue("Should have found the received ringer mode in the expected ringerMode values", found); }
Example 16
Source File: DeviceEventUpdatesProvider.java From PrivacyStreams with Apache License 2.0 | 4 votes |
@Override public void onReceive(Context context, Intent intent) { String event = null; String type = null; switch(intent.getAction()){ case Intent.ACTION_SCREEN_OFF: event = DeviceEvent.EVENT_SCREEN_OFF; type = DeviceEvent.TYPE_SCREEN; break; case Intent.ACTION_SCREEN_ON: event = DeviceEvent.EVENT_SCREEN_ON; type = DeviceEvent.TYPE_SCREEN; break; case Intent.ACTION_USER_PRESENT: event = DeviceEvent.EVENT_SCREEN_USER_PRESENT; type = DeviceEvent.TYPE_SCREEN; break; case Intent.ACTION_BOOT_COMPLETED: event = DeviceEvent.EVENT_BOOT_COMPLETED; type = DeviceEvent.TYPE_BOOT; break; case Intent.ACTION_SHUTDOWN: event = DeviceEvent.EVENT_BOOT_SHUTDOWN; type = DeviceEvent.TYPE_BOOT; break; case Intent.ACTION_BATTERY_LOW: event = DeviceEvent.EVENT_BATTERY_LOW; type = DeviceEvent.TYPE_BATTERY; break; case Intent.ACTION_BATTERY_OKAY: event = DeviceEvent.EVENT_BATTERY_OKAY; type = DeviceEvent.TYPE_BATTERY; break; case Intent.ACTION_POWER_CONNECTED: event = DeviceEvent.EVENT_BATTERY_AC_CONNECTED; type = DeviceEvent.TYPE_BATTERY; break; case Intent.ACTION_POWER_DISCONNECTED: event = DeviceEvent.EVENT_BATTERY_AC_DISCONNECTED; type = DeviceEvent.TYPE_BATTERY; break; case AudioManager.RINGER_MODE_CHANGED_ACTION: AudioManager am = (AudioManager)getContext().getSystemService(Context.AUDIO_SERVICE); switch (am.getRingerMode()) { case AudioManager.RINGER_MODE_SILENT: event = DeviceEvent.EVENT_RINGER_SILENT; type = DeviceEvent.TYPE_RINGER; break; case AudioManager.RINGER_MODE_VIBRATE: event = DeviceEvent.EVENT_RINGER_VIBRATE; type = DeviceEvent.TYPE_RINGER; break; case AudioManager.RINGER_MODE_NORMAL: event = DeviceEvent.EVENT_RINGER_NORMAL; type = DeviceEvent.TYPE_RINGER; break; } default: break; } if (type != null) output(new DeviceEvent(type, event)); }
Example 17
Source File: VibrationMessageFilter.java From android-chromium with BSD 2-Clause "Simplified" License | 4 votes |
@CalledByNative private void vibrate(long milliseconds) { if (mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_SILENT) mVibrator.vibrate(milliseconds); }
Example 18
Source File: VibrationMessageFilter.java From android-chromium with BSD 2-Clause "Simplified" License | 4 votes |
@CalledByNative private void vibrate(long milliseconds) { if (mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_SILENT) mVibrator.vibrate(milliseconds); }
Example 19
Source File: RingerModeChangeReceiver.java From PhoneProfilesPlus with Apache License 2.0 | 4 votes |
private static int getRingerMode(Context context, AudioManager audioManager) { int ringerMode = audioManager.getRingerMode(); //PPApplication.logE("RingerModeChangeReceiver.getRingerMode", "ringerMode="+ringerMode); // convert to profile ringerMode int pRingerMode = 0; //if (android.os.Build.VERSION.SDK_INT >= 21) { int systemZenMode = ActivateProfileHelper.getSystemZenMode(context/*, -1*/); //PPApplication.logE("RingerModeChangeReceiver.getRingerMode", "systemZenMode=" + systemZenMode); if (systemZenMode == ActivateProfileHelper.ZENMODE_ALL) { switch (ringerMode) { case AudioManager.RINGER_MODE_NORMAL: //if (ActivateProfileHelper.vibrationIsOn(/*context, */audioManager, false)) // pRingerMode = 2; //else pRingerMode = 1; break; case AudioManager.RINGER_MODE_VIBRATE: pRingerMode = 3; break; case AudioManager.RINGER_MODE_SILENT: pRingerMode = 4; break; } } else pRingerMode = 5; /*} else { switch (ringerMode) { case AudioManager.RINGER_MODE_NORMAL: if (ActivateProfileHelper.vibrationIsOn(audioManager, false)) pRingerMode = 2; else pRingerMode = 1; break; case AudioManager.RINGER_MODE_VIBRATE: pRingerMode = 3; break; case AudioManager.RINGER_MODE_SILENT: pRingerMode = 4; break; } }*/ //PPApplication.logE("RingerModeChangeReceiver.getRingerMode", "pRingerMode=" + pRingerMode); return pRingerMode; }
Example 20
Source File: Vibration.java From reacteu-app with MIT License | 3 votes |
/** * Vibrates the device with a given pattern. * * @param pattern Pattern with which to vibrate the device. * Pass in an array of longs that * are the durations for which to * turn on or off the vibrator in * milliseconds. The first value * indicates the number of milliseconds * to wait before turning the vibrator * on. The next value indicates the * number of milliseconds for which * to keep the vibrator on before * turning it off. Subsequent values * alternate between durations in * milliseconds to turn the vibrator * off or to turn the vibrator on. * * @param repeat Optional index into the pattern array at which * to start repeating, or -1 for no repetition (default). */ public void vibrateWithPattern(long[] pattern, int repeat) { AudioManager manager = (AudioManager) this.cordova.getActivity().getSystemService(Context.AUDIO_SERVICE); if (manager.getRingerMode() != AudioManager.RINGER_MODE_SILENT) { Vibrator vibrator = (Vibrator) this.cordova.getActivity().getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(pattern, repeat); } }