List of usage examples for android.media AudioManager RINGER_MODE_SILENT
int RINGER_MODE_SILENT
To view the source code for android.media AudioManager RINGER_MODE_SILENT.
Click Source Link
From source file:Main.java
public static void setRinger2Silent(Context context) { AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT); Log.i("HelperFunctions ", "Silent method called"); }
From source file:com.metinkale.prayerapp.vakit.AlarmReceiver.java
public static void silenter(Context c, long dur) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c); boolean silent = "silent".equals(prefs.getString("silenterType", "silent")); AudioManager aum = (AudioManager) c.getSystemService(Context.AUDIO_SERVICE); int ringermode = aum.getRingerMode(); if ((ringermode != AudioManager.RINGER_MODE_SILENT) && ((ringermode != AudioManager.RINGER_MODE_VIBRATE) || silent)) { AlarmManager am = (AlarmManager) c.getSystemService(Context.ALARM_SERVICE); Intent i;/*from w w w.j av a2s .co m*/ if (ringermode == AudioManager.RINGER_MODE_VIBRATE) { i = new Intent(c, setVibrate.class); } else { i = new Intent(c, setNormal.class); } PendingIntent service = PendingIntent.getBroadcast(c, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (1000 * 60 * dur), service); if (PermissionUtils.get(c).pNotPolicy) aum.setRingerMode(silent ? AudioManager.RINGER_MODE_SILENT : AudioManager.RINGER_MODE_VIBRATE); } }
From source file:com.kyakujin.android.autoeco.ui.SilentModeSettingFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { mActivity = getActivity();//from ww w .ja va 2 s . c o m LayoutInflater inflater = getActivity().getLayoutInflater(); View view = inflater.inflate(R.layout.fragment_dialog_silentmode, null, false); RadioGroup radioGroup = (RadioGroup) view.findViewById(R.id.radioGroupSilentMode); // ????????? radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.radioNormal: mSilentMode = AudioManager.RINGER_MODE_NORMAL; break; case R.id.radioSilent: mSilentMode = AudioManager.RINGER_MODE_SILENT; break; case R.id.radioVibrate: mSilentMode = AudioManager.RINGER_MODE_VIBRATE; break; default: } } }); mCurrentEcoId = getArguments().getInt(Conf.SHARED_ECOID); mSilentMode = getArguments().getInt(Conf.SHARED_SILENTMODE); switch (mSilentMode) { case AudioManager.RINGER_MODE_NORMAL: radioGroup.check(R.id.radioNormal); break; case AudioManager.RINGER_MODE_SILENT: radioGroup.check(R.id.radioSilent); break; case AudioManager.RINGER_MODE_VIBRATE: radioGroup.check(R.id.radioVibrate); break; default: } AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.setting_silent); builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { EcoDAO dao = new EcoDAO(mActivity); dao.updateSilentMode(mCurrentEcoId, mSilentMode); } }); builder.setNegativeButton("Cancel", null); builder.setView(view); return builder.create(); }
From source file:com.intellisol.plugin.Ringer.java
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if (NATIVE_ACTION_STRING.equals(action)) { int mode; try {//from w w w . j a v a2 s.c om // get mode from argument mode = args.getInt(0); // get context (Android) Context ctxt = cordova.getActivity().getBaseContext(); if (mode == NORMAL) { // set ringer mode AudioManager audioManager = (AudioManager) ctxt.getSystemService(Context.AUDIO_SERVICE); audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); } else if (mode == VIBRATE) { AudioManager audioManager = (AudioManager) ctxt.getSystemService(Context.AUDIO_SERVICE); audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); } else if (mode == SILENT) { AudioManager audioManager = (AudioManager) ctxt.getSystemService(Context.AUDIO_SERVICE); audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT); } } catch (JSONException e) { // log error Log.d("Ringer", e.toString()); return false; } catch (Exception e) { // log error Log.d("Ringer", e.toString()); return false; } } return true; }
From source file:com.prey.actions.picture.PictureUtil.java
private static byte[] getPicture(Context ctx, String focus) { AudioManager mgr = null;/* ww w . j av a 2 s. com*/ SimpleCameraActivity.dataImagen = null; int streamType = AudioManager.STREAM_SYSTEM; SimpleCameraActivity.activity = null; Intent intent = new Intent(ctx, SimpleCameraActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra("focus", focus); ctx.startActivity(intent); int i = 0; mgr = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE); mgr.setStreamSolo(streamType, true); mgr.setRingerMode(AudioManager.RINGER_MODE_SILENT); mgr.setStreamMute(streamType, true); while (SimpleCameraActivity.activity == null && i < 10) { try { Thread.sleep(1000); } catch (InterruptedException e) { } i++; } if (SimpleCameraActivity.activity != null) { SimpleCameraActivity.activity.takePicture(ctx, focus); } try { Thread.sleep(4000); } catch (InterruptedException e) { } mgr.setStreamSolo(streamType, false); mgr.setRingerMode(AudioManager.RINGER_MODE_NORMAL); mgr.setStreamMute(streamType, false); try { i = 0; while (SimpleCameraActivity.activity != null && SimpleCameraActivity.dataImagen == null && i < 5) { Thread.sleep(2000); i++; } } catch (InterruptedException e) { PreyLogger.i("Error:" + e.getMessage()); } byte[] out = null; if (SimpleCameraActivity.activity != null) { out = SimpleCameraActivity.dataImagen; SimpleCameraActivity.activity.finish(); SimpleCameraActivity.activity = null; SimpleCameraActivity.dataImagen = null; } return out; }
From source file:com.appsaur.tarucassist.AutomuteAlarmReceiver.java
@Override public void onReceive(Context context, Intent intent) { int mReceivedID = Integer.parseInt(intent.getStringExtra(BaseActivity.EXTRA_REMINDER_ID)); // Get notification title from Reminder Database ScheduleAutomuteDataSource scheduleAutomuteDataSource = new ScheduleAutomuteDataSource(context); scheduleAutomuteDataSource.open();//from w w w . j a v a 2s.c om ScheduleAutomute scheduleAutomute = scheduleAutomuteDataSource.getScheduleAutomute(mReceivedID); mCalendar = Calendar.getInstance(); myAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); if (scheduleAutomute.getAutomuteMode().equals("Vibrate")) { myAudioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); } else if (scheduleAutomute.getAutomuteMode().equals("Silent")) { myAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT); } else if (scheduleAutomute.getAutomuteMode().equals("Normal")) myAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); }
From source file:com.kaliturin.blacklist.utils.Notifications.java
private static void notify(Context context, String title, String message, String ticker, @DrawableRes int icon, String action, Uri ringtone, boolean vibration) { // turn off sound and vibration if phone is in silent mode AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); switch (am.getRingerMode()) { case AudioManager.RINGER_MODE_SILENT: ringtone = null;/* w ww . ja v a2 s . c o m*/ vibration = false; break; case AudioManager.RINGER_MODE_VIBRATE: ringtone = null; break; case AudioManager.RINGER_MODE_NORMAL: break; } // pending intent for activating app on click in status bar Intent intent = new Intent(context, MainActivity.class); intent.setAction(action); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); // build notification NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setContentIntent(pendingIntent); builder.setContentTitle(title); builder.setTicker(ticker); builder.setContentText(message); builder.setSmallIcon(icon); builder.setColor(getColor(context, R.attr.colorAccent)); builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher)); builder.setPriority(PRIORITY_MAX); builder.setAutoCancel(true); if (ringtone != null) { builder.setSound(ringtone); } if (vibration) { builder.setVibrate(new long[] { 0, 300, 300, 300 }); } NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, builder.build()); }
From source file:com.sublimis.urgentcallfilter.Magic.java
private boolean isRingerInRightMode() { boolean retVal = false; if (mAudioManager != null) { int ringerScope = MyPreference.getScope(); switch (mRingerModeOriginal) { case AudioManager.RINGER_MODE_SILENT: if ((ringerScope & 1) != 0) retVal = true;//from ww w . j a v a2 s .com break; case AudioManager.RINGER_MODE_VIBRATE: if ((ringerScope & 2) != 0) retVal = true; break; case AudioManager.RINGER_MODE_NORMAL: if ((ringerScope & 4) != 0) { if (mVolumeOriginal < mVolumeMax) retVal = true; } break; } } return retVal; }
From source file:com.z3r0byte.magis.Services.AutoSilentService.java
private void setup() { if (autoSilent) { TimerTask notificationTask = new TimerTask() { @Override/* w w w .j ava 2s .c om*/ public void run() { NotificationManager notificationManager = (NotificationManager) getApplicationContext() .getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && !notificationManager.isNotificationPolicyAccessGranted()) { Log.w(TAG, "run: Not allowed to change state of do not disturb!"); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( getApplicationContext()); mBuilder.setSmallIcon(R.drawable.magis512); Intent resultIntent = new Intent( android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS); TaskStackBuilder stackBuilder = TaskStackBuilder.create(getApplicationContext()); stackBuilder.addParentStack(CalendarActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); mBuilder.setContentTitle("Magis kan de telefoon niet op stil zetten"); mBuilder.setContentText("Klik om op te lossen"); mBuilder.setAutoCancel(true); mBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(9999, mBuilder.build()); return; } appointments = calendarDB.getSilentAppointments(getMargin()); if (doSilent(appointments)) { silenced(true); AudioManager audiomanager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); if (audiomanager.getRingerMode() != AudioManager.RINGER_MODE_SILENT) { audiomanager.setRingerMode(AudioManager.RINGER_MODE_SILENT); } } else { if (isSilencedByApp()) { AudioManager audiomanager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); audiomanager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); silenced(false); } } } }; timer.schedule(notificationTask, 20000, 1000); } }
From source file:com.zion.htf.receiver.AlarmReceiver.java
@Override public void onReceive(Context context, Intent intent) { // Get preferences Resources res = context.getResources(); SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context); int setId, alarmId; try {/*from w w w .j a va2 s .c o m*/ if (0 == (setId = intent.getIntExtra("set_id", 0))) throw new MissingArgumentException("set_id", "int"); if (0 == (alarmId = intent.getIntExtra("alarm_id", 0))) throw new MissingArgumentException("alarm_id", "int"); } catch (MissingArgumentException e) { throw new RuntimeException(e.getMessage()); } // Fetch info about the set try { // VIBRATE will be added if user did NOT disable notification vibration // SOUND won't as it is set even if it is to the default value int flags = Notification.DEFAULT_LIGHTS; MusicSet set = MusicSet.getById(setId); Artist artist = set.getArtist(); SimpleDateFormat dateFormat; if ("fr".equals(Locale.getDefault().getLanguage())) { dateFormat = new SimpleDateFormat("HH:mm", Locale.FRANCE); } else { dateFormat = new SimpleDateFormat("h:mm aa", Locale.ENGLISH); } // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(context, ArtistDetailsActivity.class); resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);// Do not start a new activity but reuse the existing one (if any) resultIntent.putExtra(ArtistDetailsActivity.EXTRA_SET_ID, setId); // Manipulate the TaskStack in order to get a good back button behaviour. See http://developer.android.com/guide/topics/ui/notifiers/notifications.html TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(ArtistDetailsActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Extract a bitmap from a file to use a large icon Bitmap largeIconBitmap = BitmapFactory.decodeResource(context.getResources(), artist.getPictureResourceId()); // Builds the notification NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) .setPriority(NotificationCompat.PRIORITY_MAX).setSmallIcon(R.drawable.ic_stat_notify_app_icon) .setLargeIcon(largeIconBitmap).setAutoCancel(true).setContentIntent(resultPendingIntent) .setContentTitle(artist.getName()) .setContentText(String.format(context.getString(R.string.alarm_notification), artist.getName(), set.getStage(), dateFormat.format(set.getBeginDate()))); // Vibrate settings Boolean defaultVibrate = true; if (!pref.contains(res.getString(R.string.pref_key_notifications_alarms_vibrate))) { // Get the system default for the vibrate setting AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); if (null != audioManager) { switch (audioManager.getRingerMode()) { case AudioManager.RINGER_MODE_SILENT: defaultVibrate = false; break; case AudioManager.RINGER_MODE_NORMAL: case AudioManager.RINGER_MODE_VIBRATE: default: defaultVibrate = true; } } } Boolean vibrate = pref.getBoolean(res.getString(R.string.pref_key_notifications_alarms_vibrate), defaultVibrate); // Ringtone settings String ringtone = pref.getString(res.getString(R.string.pref_key_notifications_alarms_ringtone), Settings.System.DEFAULT_NOTIFICATION_URI.toString()); // Apply notification settings if (!vibrate) { notificationBuilder.setVibrate(new long[] { 0l }); } else { flags |= Notification.DEFAULT_VIBRATE; } notificationBuilder.setSound(Uri.parse(ringtone)); // Get the stage GPS coordinates try { Stage stage = Stage.getByName(set.getStage()); // Add the expandable notification buttons PendingIntent directionsButtonPendingIntent = PendingIntent .getActivity(context, 1, new Intent(Intent.ACTION_VIEW, Uri.parse(String.format(Locale.ENGLISH, "http://maps.google.com/maps?f=d&daddr=%f,%f", stage.getLatitude(), stage.getLongitude()))), Intent.FLAG_ACTIVITY_NEW_TASK); notificationBuilder.addAction(R.drawable.ic_menu_directions, context.getString(R.string.action_directions), directionsButtonPendingIntent); } catch (InconsistentDatabaseException e) { // Although this is a serious error, its impact on functionality is minimal. // Report this through piwik if (BuildConfig.DEBUG) e.printStackTrace(); } // Finalize the notification notificationBuilder.setDefaults(flags); Notification notification = notificationBuilder.build(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(set.getStage(), 0, notification); SavedAlarm.delete(alarmId); } catch (SetNotFoundException e) { throw new RuntimeException(e.getMessage()); // TODO: Notify that an alarm was planned but some error prevented to display it properly. Open AlarmManagerActivity on click // Report this through piwik } }