List of usage examples for android.media AudioManager setRingerMode
public void setRingerMode(int ringerMode)
From source file:de.spiritcroc.modular_remote.MainActivity.java
@Override protected void onPause() { super.onPause(); viewPager.removeOnPageChangeListener(this); saveConnections();// w w w.ja v a2 s . c om appWidgetHost.stopListening(); if (changedRingerMode) { changedRingerMode = false; AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); audioManager.setRingerMode(previousRingerMode); } }
From source file:com.sentaroh.android.TaskAutomation.TaskExecutor.java
final static private void executeBuiltinActionPrimitive(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse taskResponse, ActionResponse ar, String bia, String dlg_id, String en, String tn) { if (bia.equals(BUILTIN_ACTION_WIFI_ON)) { taskResponse.active_thread_ctrl.setThreadMessage(BUILTIN_ACTION_WIFI_ON); setWifiOn(taskMgrParms, envParms, util, taskResponse, ar); } else if (bia.equals(BUILTIN_ACTION_WIFI_OFF)) { taskResponse.active_thread_ctrl.setThreadMessage(BUILTIN_ACTION_WIFI_OFF); setWifiOff(taskMgrParms, envParms, util, taskResponse, ar); } else if (bia.equals(BUILTIN_ACTION_WIFI_DISABLE_CONNECTED_SSID)) { taskResponse.active_thread_ctrl.setThreadMessage(BUILTIN_ACTION_WIFI_DISABLE_CONNECTED_SSID); setWifiDisableSsid(taskMgrParms, envParms, util, taskResponse, ar); } else if (bia.equals(BUILTIN_ACTION_WIFI_REMOVE_CONNECTED_SSID)) { taskResponse.active_thread_ctrl.setThreadMessage(BUILTIN_ACTION_WIFI_REMOVE_CONNECTED_SSID); setWifiRemoveSsid(taskMgrParms, envParms, util, taskResponse, ar); } else if (bia.equals(BUILTIN_ACTION_BLUETOOTH_ON)) { taskResponse.active_thread_ctrl.setThreadMessage(BUILTIN_ACTION_BLUETOOTH_ON); setBluetoothOn(taskMgrParms, envParms, util, taskResponse, ar); } else if (bia.equals(BUILTIN_ACTION_BLUETOOTH_OFF)) { taskResponse.active_thread_ctrl.setThreadMessage(BUILTIN_ACTION_BLUETOOTH_OFF); setBluetoothOff(taskMgrParms, envParms, util, taskResponse, ar); } else if (bia.equals(BUILTIN_ACTION_WAIT_1_SEC)) { waitTimeTc(taskResponse, 1 * 1000); if (!taskResponse.active_thread_ctrl.isEnable()) { ar.action_resp = ActionResponse.ACTION_CANCELLED; ar.resp_msg_text = "Action was cancelled"; }/*w w w . j ava 2 s. c o m*/ } else if (bia.equals(BUILTIN_ACTION_WAIT_5_SEC)) { waitTimeTc(taskResponse, 5 * 1000); if (!taskResponse.active_thread_ctrl.isEnable()) { ar.action_resp = ActionResponse.ACTION_CANCELLED; ar.resp_msg_text = "Action was cancelled"; } } else if (bia.equals(BUILTIN_ACTION_WAIT_1_MIN)) { waitTimeTc(taskResponse, 1 * 60 * 1000); if (!taskResponse.active_thread_ctrl.isEnable()) { ar.action_resp = ActionResponse.ACTION_CANCELLED; ar.resp_msg_text = "Action was cancelled"; } } else if (bia.equals(BUILTIN_ACTION_WAIT_5_MIN)) { waitTimeTc(taskResponse, 5 * 60 * 1000); if (!taskResponse.active_thread_ctrl.isEnable()) { ar.action_resp = ActionResponse.ACTION_CANCELLED; ar.resp_msg_text = "Action was cancelled"; } } else if (bia.equals(BUILTIN_ACTION_SWITCH_TO_HOME)) { setScreenSwitchToHome(taskMgrParms, envParms, util, taskResponse, ar); } else if (bia.equals(BUILTIN_ACTION_SCREEN_LOCK)) { setScreenLocked(taskMgrParms, util, taskResponse, ar); } else if (bia.equals(BUILTIN_ACTION_SCREEN_ON)) { screenOnSync(taskMgrParms, taskResponse, ar); } else if (bia.equals(BUILTIN_ACTION_SCREEN_ON_ASYNC)) { screenOnAsync(taskMgrParms, taskResponse, ar); } else if (bia.equals(BUILTIN_ACTION_PLAYBACK_DEFAULT_ALARM)) { playBackDefaultAlarm(taskMgrParms, envParms, util, taskResponse, ar); } else if (bia.equals(BUILTIN_ACTION_PLAYBACK_DEFAULT_NOTIFICATION)) { playBackDefaultNotification(taskMgrParms, envParms, util, taskResponse, ar); } else if (bia.equals(BUILTIN_ACTION_PLAYBACK_DEFAULT_RINGTONE)) { playBackDefaultRingtone(taskMgrParms, envParms, util, taskResponse, ar); } else if (bia.equals(BUILTIN_ACTION_VIBRATE)) { vibrateDefaultPattern(taskMgrParms.context, ar); } else if (bia.equals(BUILTIN_ACTION_RESTART_SCHEDULER)) { sendCmdToService(taskResponse, BUILTIN_ACTION_RESTART_SCHEDULER, dlg_id, CMD_THREAD_TO_SVC_RESTART_SCHEDULER, BUILTIN_ACTION_RESTART_SCHEDULER); } else if (bia.equals(BUILTIN_ACTION_RINGER_NORMAL)) { AudioManager am = (AudioManager) taskMgrParms.context.getSystemService(Context.AUDIO_SERVICE); am.setRingerMode(AudioManager.RINGER_MODE_NORMAL); // am.setStreamMute(AudioManager.STREAM_MUSIC, false); // am.setStreamMute(AudioManager.STREAM_RING, false); // am.setStreamMute(AudioManager.STREAM_NOTIFICATION, false); // am.setStreamMute(AudioManager.STREAM_SYSTEM, false); // am.setStreamMute(AudioManager.STREAM_ALARM, false); } else if (bia.equals(BUILTIN_ACTION_RINGER_SILENT)) { AudioManager am = (AudioManager) taskMgrParms.context.getSystemService(Context.AUDIO_SERVICE); am.setRingerMode(AudioManager.RINGER_MODE_SILENT); // am.setStreamMute(AudioManager.STREAM_MUSIC, true); // am.setStreamMute(AudioManager.STREAM_RING, true); // am.setStreamMute(AudioManager.STREAM_NOTIFICATION, true); // am.setStreamMute(AudioManager.STREAM_SYSTEM, true); // am.setStreamMute(AudioManager.STREAM_ALARM, true); } else if (bia.equals(BUILTIN_ACTION_RINGER_VIBRATE)) { AudioManager am = (AudioManager) taskMgrParms.context.getSystemService(Context.AUDIO_SERVICE); am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); // am.setStreamMute(AudioManager.STREAM_MUSIC, true); // am.setStreamMute(AudioManager.STREAM_RING, true); // am.setStreamMute(AudioManager.STREAM_NOTIFICATION, true); // am.setStreamMute(AudioManager.STREAM_SYSTEM, true); // am.setStreamMute(AudioManager.STREAM_ALARM, true); } else if (bia.equals(BUILTIN_ACTION_AUTO_SYNC_ENABLED)) { setAutoSyncEnabled(taskMgrParms, envParms, util, taskResponse, ar); } else if (bia.equals(BUILTIN_ACTION_AUTO_SYNC_DISABLED)) { setAutoSyncDisabled(taskMgrParms, envParms, util, taskResponse, ar); } else if (bia.equals(BUILTIN_ACTION_ABORT)) { ar.action_resp = ActionResponse.ACTION_ABORT; ar.resp_msg_text = "Task was aborted"; } else { ar.action_resp = ActionResponse.ACTION_ERROR; ar.resp_msg_text = String.format(taskMgrParms.teMsgs.msgs_thread_task_unknoww_action, bia); } }
From source file:de.spiritcroc.modular_remote.MainActivity.java
@Override protected void onResume() { super.onResume(); appWidgetHost.startListening();/* w w w .j a va 2s .c o m*/ tcpConnectionManager.refreshConnections(); viewPager.addOnPageChangeListener(this); onPageSelected(viewPager.getCurrentItem()); int tmp = Util.getPreferenceInt(sharedPreferences, Preferences.OFFSCREEN_PAGE_LIMIT, 2); if (tmp < 0) { neverDestroyPages = true; viewPager.setOffscreenPageLimit(pages.size()); } else { neverDestroyPages = false; viewPager.setOffscreenPageLimit(tmp); } fullscreen = sharedPreferences.getBoolean(Preferences.FULLSCREEN, false); hideNavigationBar = sharedPreferences.getBoolean(Preferences.HIDE_NAVIGATION_BAR, false); hideActionBar = sharedPreferences.getBoolean(Preferences.HIDE_ACTION_BAR, false); int pagerTabStripVisibility = sharedPreferences.getBoolean(Preferences.HIDE_PAGER_TAB_STRIP, false) ? View.GONE : View.VISIBLE; if (pagerTabStrip.getVisibility() != pagerTabStripVisibility) { pagerTabStrip.setVisibility(pagerTabStripVisibility); } String ringerMode = sharedPreferences.getString(Preferences.CHANGE_RINGER_MODE, getString(R.string.pref_ringer_mode_keep_value)); AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); previousRingerMode = audioManager.getRingerMode(); if (getString(R.string.pref_ringer_mode_mute_value).equals(ringerMode)) { audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT); changedRingerMode = true; } else if (getString(R.string.pref_ringer_mode_vibrate_value).equals(ringerMode)) { audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); changedRingerMode = true; } else if (getString(R.string.pref_ringer_mode_vibrate_if_not_muted_value).equals(ringerMode) && previousRingerMode != AudioManager.RINGER_MODE_SILENT) { audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); changedRingerMode = true; } if (forceOrientation == FORCE_ORIENTATION_PORTRAIT) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else if (forceOrientation == FORCE_ORIENTATION_LANDSCAPE) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } else { String orientation = sharedPreferences.getString(Preferences.ORIENTATION, Preferences.ORIENTATION_SHARE_LAYOUT); if (Preferences.ORIENTATION_PORTRAIT_ONLY.equals(orientation)) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else if (Preferences.ORIENTATION_LANDSCAPE_ONLY.equals(orientation)) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } else { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER); } } resizeContent(); setLockedModeVisibilities(); }
From source file:com.z3r0byte.magistify.Services.BackgroundService.java
private void autoSilent() { Appointment[] appointments = calendarDB.getSilentAppointments(getMargin()); if (doSilent(appointments)) { setSilenced(true);// www .java 2s . c o m AudioManager audiomanager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); if (audiomanager == null) return; if (!isSilencedByApp()) configUtil.setInteger("previous_silent_state", audiomanager.getRingerMode()); if (audiomanager.getRingerMode() != AudioManager.RINGER_MODE_SILENT) { audiomanager.setRingerMode(AudioManager.RINGER_MODE_SILENT); } } else { if (isSilencedByApp()) { AudioManager audiomanager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); if (audiomanager == null) return; if (configUtil.getBoolean("reverse_silent_state")) { audiomanager.setRingerMode(configUtil.getInteger("previous_silent_state")); } else { audiomanager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); } setSilenced(false); } } }
From source file:com.android.launcher3.Utilities.java
public static void modeSilent(Activity activity) { checkPermissionForRingtone(activity); AudioManager mobilemode = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE); if (isModeSilent) { mobilemode.setRingerMode(mobileModeSilentPrevious); isModeSilent = false;/*from ww w . jav a2s . c o m*/ } else { isModeSilent = true; mobileModeSilentPrevious = mobilemode.getRingerMode(); mobilemode.setRingerMode(AudioManager.RINGER_MODE_SILENT); } }
From source file:com.android.launcher3.Utilities.java
public static void modeNormal(Activity activity) { checkPermissionForRingtone(activity); AudioManager mobilemode = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE); if (isModeNormal) { mobilemode.setRingerMode(mobileModeNormalPrevious); isModeNormal = false;/*from w w w . j av a 2 s .com*/ } else { isModeNormal = true; mobileModeNormalPrevious = mobilemode.getRingerMode(); mobilemode.setRingerMode(AudioManager.RINGER_MODE_NORMAL); } }
From source file:com.android.launcher3.Utilities.java
public static void modeVibrate(Activity activity) { checkPermissionForRingtone(activity); AudioManager mobilemode = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE); if (isModeVibrate) { mobilemode.setRingerMode(mobileModeVibratePrevious); isModeVibrate = false;//ww w. j a va 2 s.c o m } else { isModeVibrate = true; mobileModeVibratePrevious = mobilemode.getRingerMode(); mobilemode.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); } }
From source file:ibme.sleepap.recording.SignalsRecorder.java
protected void stopRecording() { // Cancel dialogs. if (delayAlertDialog != null) { delayAlertDialog.cancel();//www .j a va 2s . com } // Unregister listeners. try { if (ppgEnabled) { unregisterReceiver(bluetoothDisconnectReceiver); } } catch (Exception e) { Log.e(Constants.CODE_APP_TAG, "Error unregistering bluetooth disconnect BroadcastReceiver", e); } try { unregisterReceiver(batteryLevelReceiver); } catch (Exception e) { Log.e(Constants.CODE_APP_TAG, "Error unregistering bluetooth disconnect BroadcastReceiver", e); } // Stop graphs update. if (graphUpdateTask.isRunning()) { graphUpdateTask.stopUiUpdates(); } // Audio if (audioEnabled) { extAudioRecorder.stop(); extAudioRecorder.release(); } // PPG if (ppgEnabled) { noninManager.prepareToStop(); } // Actigraphy if (actigraphyEnabled) { sensorManager.unregisterListener(this); } try { wakeLock.release(); } catch (Throwable t) { Log.e(Constants.CODE_APP_TAG, "Wakelock has already been released", t); } // Check if we have both stopped and started recording properly. If we // have, everything has worked properly. If we haven't, user probably // interrupted recordings and we should delete the files they made. boolean shouldDelete = sharedPreferences.getBoolean(Constants.PREF_EARLY_EXIT_DELETION, Constants.DEFAULT_EARLY_EXIT_DELETION); boolean recordingSuccessful = startRecordingFlag && finishRecordingFlag; if (shouldDelete && !recordingSuccessful) { // User interrupted recording. Recordings are useless - get rid of // them. if (filesDirPath != null) { File filesDir = new File(filesDirPath); Utils.deleteDirectory(filesDir); } } else { // Otherwise save the position data - woudn't need to do this if // files were to be deleted. saveBodyPositionData(); } // Cancel recording notification. if (sharedPreferences.getBoolean(Constants.PREF_NOTIFICATIONS, Constants.DEFAULT_NOTIFICATIONS)) { notificationManager.cancel(Constants.CODE_APP_NOTIFICATION_ID); } recordingSign.setVisibility(View.GONE); // Let the user know the recording is over. AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); dialogBuilder.setTitle(getString(R.string.finishedAlertTitle)); if (shouldDelete && !recordingSuccessful) { dialogBuilder.setMessage(getString(R.string.finishedAlertFailure)); } else { dialogBuilder.setMessage(getString(R.string.finishedAlertSuccess)); dialogBuilder.setNegativeButton(getString(R.string.analyseButtonText), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(SignalsRecorder.this, ChooseData.class); File recordingDir = new File(filesDirPath); intent.putExtra(Constants.EXTRA_RECORDING_DIRECTORY, recordingDir); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); finish(); } }); } dialogBuilder.setPositiveButton(getString(R.string.mainMenuButtonText), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(SignalsRecorder.this, MainMenu.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } }); dialogBuilder.setCancelable(false); dialogBuilder.create().show(); // Change logcat back if necessary. if (sharedPreferences.getBoolean(Constants.PREF_WRITE_LOG, Constants.DEFAULT_WRITE_LOG)) { String[] cmd = new String[] { "logcat", "-f", "stdout", "*:V" }; try { Runtime.getRuntime().exec(cmd); } catch (IOException e) { Log.e(Constants.CODE_APP_TAG, "Error changing logcat back to default", e); } } // Reset phone ringing mode to what it was before user changed it to // silent. AudioManager am = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE); am.setRingerMode(extras.getInt(Constants.EXTRA_RING_SETTING)); }
From source file:edu.cmu.mpcs.dashboard.TagViewer.java
private String ringerSetting(String settingString) { /*****//from w w w .jav a 2 s . c om * Setting the phone on Silent, Vibrate and Normal modes *****/ if (settingString.contains("ringer")) { AudioManager audMangr; audMangr = (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE); // For Normal mode // audMangr.setRingerMode(AudioManager.RINGER_MODE_NORMAL); // For Silent mode // audMangr.setRingerMode(AudioManager.RINGER_MODE_SILENT); // For vibrate // audMangr.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); if (settingString.contains("ringer:Loud")) { audMangr.setRingerMode(AudioManager.RINGER_MODE_NORMAL); return ("Phone Ringer:Loud\n"); } else { audMangr.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); return ("Phone Ringer:Vibrate\n"); } /* Adjusting volume */ // if (audMangr.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) // { // Log.d("RINGER", "setting ringer to silent"); // audMangr.setRingerMode(AudioManager.RINGER_MODE_SILENT); // audMangr.adjustVolume(AudioManager.ADJUST_LOWER, 0); // // } else { // Log.d("RINGER", "setting ringer to normal"); // // // } } return (""); }
From source file:com.bangz.smartmute.services.LocationMuteService.java
private void handleGeofenceTrigger(Intent intent) { LogUtils.LOGD(TAG, "Handling Geofence trigger ..."); HashMap<Integer, String> mapRingerMode = new HashMap<Integer, String>(); mapRingerMode.put(AudioManager.RINGER_MODE_NORMAL, "Normal"); mapRingerMode.put(AudioManager.RINGER_MODE_SILENT, "Silent"); mapRingerMode.put(AudioManager.RINGER_MODE_VIBRATE, "Vibrate"); HashMap<Integer, String> mapTransition = new HashMap<Integer, String>(); mapTransition.put(Geofence.GEOFENCE_TRANSITION_DWELL, "DWELL"); mapTransition.put(Geofence.GEOFENCE_TRANSITION_ENTER, "ENTER"); mapTransition.put(Geofence.GEOFENCE_TRANSITION_EXIT, "EXIT"); GeofencingEvent geoEvent = GeofencingEvent.fromIntent(intent); if (geoEvent.hasError() == false) { LogUtils.LOGD(TAG, "\tgeoEvent has no error."); AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); if (audioManager == null) { LogUtils.LOGD(TAG, "\t !!!!! AudioManager == null !!!!!!!"); return; }/*from w w w .ja v a2s . c om*/ int currringermode = audioManager.getRingerMode(); List<Geofence> geofences = geoEvent.getTriggeringGeofences(); int transition = geoEvent.getGeofenceTransition(); ContentResolver cr = getContentResolver(); //int enterTransition = Config.TEST_BUILD ? Geofence.GEOFENCE_TRANSITION_ENTER : Geofence.GEOFENCE_TRANSITION_DWELL; LogUtils.LOGD(TAG, "\tTransition: " + mapTransition.get(transition)); if (transition == Geofence.GEOFENCE_TRANSITION_DWELL || transition == Geofence.GEOFENCE_TRANSITION_ENTER) { boolean setted = false; for (Geofence geofence : geofences) { long id = Long.parseLong(geofence.getRequestId()); Uri uri = ContentUris.withAppendedId(RulesColumns.CONTENT_ID_URI_BASE, id); Cursor cursor = cr.query(uri, PROJECTS, RulesColumns.ACTIVATED + " = 1", null, null); if (cursor.getCount() != 0) { cursor.moveToFirst(); int setmode = cursor.getInt(cursor.getColumnIndex(RulesColumns.RINGMODE)); if (currringermode == setmode) { LogUtils.LOGD(TAG, "\tringer mode already is in silent or vibrate. we do nothing"); } else { LogUtils.LOGD(TAG, "\tset ringer mode to " + setmode); audioManager.setRingerMode(setmode); PrefUtils.rememberWhoMuted(this, id); //TODO Notify to user ? } setted = true; } else { LogUtils.LOGD(TAG, "\tid = " + id + " trigger, but does not find in database. maybe disabled."); } cursor.close(); cursor = null; if (setted == true) { break; } } } else if (transition == Geofence.GEOFENCE_TRANSITION_EXIT) { for (Geofence geofence : geofences) { long id = Long.parseLong(geofence.getRequestId()); if (id == PrefUtils.getLastSetMuteId(this)) { AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); if (am != null) { am.setRingerMode(AudioManager.RINGER_MODE_NORMAL); } PrefUtils.cleanLastMuteId(this); break; } } } else { LogUtils.LOGD(TAG, "transition is " + transition + " ; != entertransition && !! EXIT"); } } else { PrefUtils.Geofencing(this, false); if (geoEvent.getErrorCode() == GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE) { NotificationUserFailed(); ReceUtils.enableReceiver(this, LocationProviderChangedReceiver.class, true); } else { LogUtils.LOGD(TAG, "\tHandle Geofence trigger error. errcode = " + geoEvent.getErrorCode()); } } LogUtils.LOGD(TAG, "Successful Leave handling Geofence trigger."); }