Java Code Examples for android.media.AudioManager#setRingerMode()
The following examples show how to use
android.media.AudioManager#setRingerMode() .
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: RingerModeTransition.java From Noyze with Apache License 2.0 | 6 votes |
/** * @return An ordered list of the ringer modes, from * highest to lowest (volumes [1], [0], [0] again). */ public int[] apply(AudioManager manager) { // The algorithm here is to go from volume 0 (again) => 0 => 1, // and with each change, record the ringer modes. final int[] MODES = new int[3]; MODES[0] = RINGER_MODE_NORMAL; final int STREAM = STREAM_RING; final int MODE = manager.getRingerMode(); final int startVolume = manager.getStreamVolume(STREAM); // API quirk: volume must be decremented from 1 to get ringer mode change manager.setStreamVolume(STREAM, 1, FLAG_SHOW_UI); manager.setRingerMode(RINGER_MODE_NORMAL); manager.adjustStreamVolume(STREAM, ADJUST_LOWER, FLAG_SHOW_UI & FLAG_ALLOW_RINGER_MODES); manager.adjustStreamVolume(STREAM, ADJUST_LOWER, FLAG_SHOW_UI & FLAG_ALLOW_RINGER_MODES); MODES[2] = manager.getRingerMode(); manager.adjustStreamVolume(STREAM, ADJUST_RAISE, FLAG_SHOW_UI & FLAG_ALLOW_RINGER_MODES); MODES[1] = manager.getRingerMode(); // There are two possible ways the device may work. It may have a silent/vibrate // mode or it may have distinct silent and vibrate modes. manager.setStreamVolume(STREAM, startVolume, 0); manager.setRingerMode(MODE); return MODES; }
Example 2
Source File: AudioUtils.java From SimpleSmsRemote with MIT License | 6 votes |
/** * Set volume as index. * * @param context app context * @param volumeIndex volume as index (max. is depends on device) * @param type audio type */ public static void SetVolumeIndex(Context context, int volumeIndex, AudioType type) { int ringerMode = -1; if (type == AudioType.RING && volumeIndex == VOLUME_INDEX_RING_VIBRATE) { volumeIndex = 0; ringerMode = AudioManager.RINGER_MODE_VIBRATE; } else if (type == AudioType.RING && volumeIndex == VOLUME_INDEX_RING_SILENT) { volumeIndex = 0; ringerMode = AudioManager.RINGER_MODE_SILENT; } else if (volumeIndex < 0) volumeIndex = 0; AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); audioManager.setStreamVolume(type.getStreamType(), volumeIndex, 0); if (ringerMode != -1) audioManager.setRingerMode(ringerMode); }
Example 3
Source File: RingerModeLoader.java From Easer with GNU General Public License v3.0 | 6 votes |
private static boolean amSetMode(AudioManager audioManager, RingerMode mode) { int am_mode; switch (mode) { case silent: am_mode = AudioManager.RINGER_MODE_SILENT; break; case vibrate: am_mode = AudioManager.RINGER_MODE_VIBRATE; break; case normal: am_mode = AudioManager.RINGER_MODE_NORMAL; break; default: Logger.w("Running on below Lollipop, but ringer mode %s found", mode); return false; } audioManager.setRingerMode(am_mode); if (audioManager.getRingerMode() == am_mode) { return true; } else { Logger.e("not properly set ringer mode :: expected <%s> got <%s>", mode, audioManager.getRingerMode()); return false; } }
Example 4
Source File: Sound.java From Android-Audio-Recorder with Apache License 2.0 | 6 votes |
public void silent() { SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(context); if (shared.getBoolean(MainApplication.PREFERENCE_SILENT, false)) { AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); soundMode = am.getRingerMode(); if (soundMode == AudioManager.RINGER_MODE_SILENT) { // we already in SILENT mode. keep all unchanged. soundMode = -1; return; } am.setStreamVolume(AudioManager.STREAM_RING, am.getStreamVolume(AudioManager.STREAM_RING), AudioManager.FLAG_SHOW_UI); am.setRingerMode(AudioManager.RINGER_MODE_SILENT); } }
Example 5
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 6
Source File: RingerModeTransition.java From Noyze with Apache License 2.0 | 6 votes |
/** * @return An ordered list of the ringer modes, from * highest to lowest (volumes [1], [0], [0] again). */ public int[] apply(AudioManager manager) { // The algorithm here is to go from volume 0 (again) => 0 => 1, // and with each change, record the ringer modes. final int[] MODES = new int[3]; MODES[0] = RINGER_MODE_NORMAL; final int STREAM = STREAM_RING; final int MODE = manager.getRingerMode(); final int startVolume = manager.getStreamVolume(STREAM); // API quirk: volume must be decremented from 1 to get ringer mode change manager.setStreamVolume(STREAM, 1, FLAG_SHOW_UI); manager.setRingerMode(RINGER_MODE_NORMAL); manager.adjustStreamVolume(STREAM, ADJUST_LOWER, FLAG_SHOW_UI & FLAG_ALLOW_RINGER_MODES); manager.adjustStreamVolume(STREAM, ADJUST_LOWER, FLAG_SHOW_UI & FLAG_ALLOW_RINGER_MODES); MODES[2] = manager.getRingerMode(); manager.adjustStreamVolume(STREAM, ADJUST_RAISE, FLAG_SHOW_UI & FLAG_ALLOW_RINGER_MODES); MODES[1] = manager.getRingerMode(); // There are two possible ways the device may work. It may have a silent/vibrate // mode or it may have distinct silent and vibrate modes. manager.setStreamVolume(STREAM, startVolume, 0); manager.setRingerMode(MODE); return MODES; }
Example 7
Source File: SilentOffAction.java From beaconloc with Apache License 2.0 | 5 votes |
@Override public String execute(Context context) { final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); int ringerMode = audioManager.getRingerMode(); int old_mode = PreferencesUtil.getSilentModeProfile(context); if (ringerMode != AudioManager.RINGER_MODE_VIBRATE) { audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); } return super.execute(context); }
Example 8
Source File: SilentOnAction.java From beaconloc with Apache License 2.0 | 5 votes |
@Override public String execute(Context context) { final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) { audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT); mRingerMode = AudioManager.RINGER_MODE_NORMAL; } else if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) { audioManager.setMode(AudioManager.RINGER_MODE_SILENT); mRingerMode = AudioManager.RINGER_MODE_VIBRATE; } PreferencesUtil.setSilentModeProfile(context, mRingerMode); audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT); return super.execute(context); }
Example 9
Source File: SilenterReceiver.java From prayer-times-android with Apache License 2.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { if (PermissionUtils.get(context).pNotPolicy && intent.hasExtra("mode")) { AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); am.setRingerMode(intent.getIntExtra("mode", 0)); } }
Example 10
Source File: SilenterReceiver.java From prayer-times-android with Apache License 2.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { if (PermissionUtils.get(context).pNotPolicy && intent.hasExtra("mode")) { AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); am.setRingerMode(intent.getIntExtra("mode", 0)); } }
Example 11
Source File: SettingsActionService.java From LibreTasks with Apache License 2.0 | 5 votes |
/** * set the phone to silent */ private void setPhoneSilent() { AudioManager audioManager =(AudioManager) getSystemService(Context.AUDIO_SERVICE); audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT); ResultProcessor.process(this, intent, ResultProcessor.RESULT_SUCCESS, getString(R.string.phone_set_silent)); }
Example 12
Source File: SettingsActionService.java From LibreTasks with Apache License 2.0 | 5 votes |
/** * set the phone to loud */ private void setPhoneLoud() { AudioManager audioManager =(AudioManager) getSystemService(Context.AUDIO_SERVICE); audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); int ringstream = AudioManager.STREAM_RING; int ringmaxvolume = audioManager.getStreamMaxVolume(ringstream); audioManager.setStreamVolume(ringstream, ringmaxvolume, AudioManager.FLAG_SHOW_UI); ResultProcessor.process(this, intent, ResultProcessor.RESULT_SUCCESS, getString(R.string.phone_set_loud)); }
Example 13
Source File: Configuration.java From iSCAU-Android with GNU General Public License v3.0 | 5 votes |
@Click void btn_save(){ int server = Integer.valueOf(param_server.getSelectedParam()); boolean isFirstScreen = param_classTableAsFirstScreen.getYesOrNo(); AppContext.server = server; config.eduServer().put(server); config.classTableAsFirstScreen().put(isFirstScreen); RingerMode[] modes = RingerMode.values(); RingerMode duringMode = modes[param_ringer_mode_during_class.getWheel().getCurrentItem()]; RingerMode afterMode = modes[param_ringer_mode_after_class.getWheel().getCurrentItem()]; boolean needUpdateAlarm = false; if(RingerMode.isSet(config.duringClassRingerMode().get()) != RingerMode.isSet(duringMode.getValue()) || RingerMode.isSet(config.afterClassRingerMode().get()) != RingerMode.isSet(afterMode.getValue())){ needUpdateAlarm = true; } config.duringClassRingerMode().put(duringMode.getValue()); config.afterClassRingerMode().put(afterMode.getValue()); if(needUpdateAlarm){ RingerMode.duringClassOn(getActivity(), duringMode, -1); RingerMode.afterClassOn(getActivity(), afterMode, 1); } if(RingerMode.isSet(duringMode.getValue()) || RingerMode.isSet(afterMode.getValue())){ RingerMode.setDateChangedAlarm(getActivity()); } else { RingerMode.cancelDateChangedAlarm(getActivity()); } AudioManager audioManager = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); if(ClassUtil.isDuringClassNow(getActivity())){ audioManager.setRingerMode(duringMode.getValue()); } else { audioManager.setRingerMode(afterMode.getValue()); } AppMsg.makeText(parentActivity(),R.string.tips_save_successfully,AppMsg.STYLE_INFO).show(); }
Example 14
Source File: PlayAudioPresenter.java From microbit with Apache License 2.0 | 5 votes |
private void preparePhoneToPlayAudio(Context context) { audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); originalRingerMode = audioManager.getRingerMode(); originalRingerMode = audioManager.getRingerMode(); originalRingerVolume = audioManager.getStreamVolume(AudioManager.STREAM_NOTIFICATION); if(originalRingerMode != AudioManager.RINGER_MODE_NORMAL) { audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); } audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, audioManager.getStreamMaxVolume (AudioManager.STREAM_NOTIFICATION), 0); }
Example 15
Source File: SilentMoodAlarm.java From MuslimMateAndroid with GNU General Public License v3.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { MindtrackLog.add("Silent Mood"); AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT); if (ConfigPreferences.getVibrationMode(context)) mAudioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); Alarms.NormalAudio(context); }
Example 16
Source File: AudioManagerUtils.java From DevUtils with Apache License 2.0 | 5 votes |
/** * 获取当前的铃声模式 * <pre> * 有下述几种模式: * RINGER_MODE_NORMAL( 普通 ) * RINGER_MODE_SILENT( 静音 ) * RINGER_MODE_VIBRATE( 震动 ) * </pre> * @param ringerMode 铃声模式 * @param setting 如果没授权, 是否跳转到设置页面 * @return {@code true} success, {@code false} fail */ public static boolean setRingerMode(final int ringerMode, final boolean setting) { AudioManager audioManager = AppUtils.getAudioManager(); if (audioManager != null) { try { if (isDoNotDisturb(setting)) { audioManager.setRingerMode(ringerMode); return true; } } catch (Exception e) { LogPrintUtils.eTag(TAG, e, "setRingerMode"); } } return false; }
Example 17
Source File: CourseVibrateAlarmService.java From KUAS-AP-Material with MIT License | 4 votes |
@Override public int onStartCommand(Intent intent, int flags, int startId) { acquireCpuWakelock(); // If user doesn't select "course" in settings, then don't show the notification. if (!Memory.getBoolean(this, Constant.PREF_COURSE_VIBRATE, false)) { stopService(); if (intent == null) { return START_STICKY; } else { return super.onStartCommand(intent, flags, startId); } } if (intent == null) { stopService(); return START_STICKY; } Bundle bundle = intent.getExtras(); if (bundle == null) { stopService(); return START_STICKY; } Boolean isVibrate = bundle.getBoolean("mode", false); AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE); if (isVibrate) { Memory.setInt(this, Constant.PREF_COURSE_VIBRATE_USER_SETTING, audioManager.getRingerMode()); audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); } else { audioManager.setRingerMode( Memory.getInt(this, Constant.PREF_COURSE_VIBRATE_USER_SETTING, audioManager.getRingerMode())); } stopService(); return super.onStartCommand(intent, flags, startId); }
Example 18
Source File: Telephony.java From experimental-fall-detector-android-app with MIT License | 4 votes |
public static void ringing(Context context) { if (-1 != undo) { AudioManager manager = (AudioManager) context.getApplicationContext().getSystemService(Context.AUDIO_SERVICE); manager.setRingerMode(undo); } }
Example 19
Source File: SilenterReceiver.java From prayer-times-android with Apache License 2.0 | 4 votes |
public static void silent(Context c, int mins) { if (!PermissionUtils.get(c).pNotPolicy && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { androidx.core.app.NotificationCompat.Builder builder; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { builder = new androidx.core.app.NotificationCompat.Builder(c, NotificationUtils.getPlayingChannel(c)); } else { builder = new NotificationCompat.Builder(c); } builder = builder.setContentTitle(c.getString(R.string.silenterNotificationTitle)) .setContentText(c.getString(R.string.silenterNotificationInfo)) .setContentIntent(PendingIntent.getActivity(c, 0, new Intent(android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS), 0)) .setSmallIcon(R.drawable.ic_abicon); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { builder.setChannelId(NotificationUtils.getAlarmChannel(c)); } else { builder.setPriority(Notification.PRIORITY_DEFAULT); } NotificationManager nm = (NotificationManager) c.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify("silenter", 557457, builder.build()); return; } AudioManager aum = (AudioManager) c.getSystemService(Context.AUDIO_SERVICE); int ringermode = aum.getRingerMode(); boolean modeVibrate = "vibrate".equals(Preferences.SILENTER_MODE.get()); boolean isSilent = ringermode == AudioManager.RINGER_MODE_SILENT; boolean isVibrate = ringermode == AudioManager.RINGER_MODE_VIBRATE; if ((modeVibrate && !isVibrate && !isSilent) || (!modeVibrate && !isSilent)) { AlarmManager am = (AlarmManager) c.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(c, SilenterReceiver.class); i.putExtra("mode", ringermode); PendingIntent service = PendingIntent.getBroadcast(c, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (1000 * 60 * mins), service); aum.setRingerMode(modeVibrate ? AudioManager.RINGER_MODE_VIBRATE : AudioManager.RINGER_MODE_SILENT); } }
Example 20
Source File: RingingAlarm.java From MuslimMateAndroid with GNU General Public License v3.0 | 4 votes |
@Override public void onReceive(Context context, Intent intent) { MindtrackLog.add("Normal Mood"); mAudioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE); mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); }