@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case RINGTONE_DIALOG_ID: { if (resultCode == RESULT_OK) { Variables.ringtoneUri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); Ringtone ringtone = RingtoneManager.getRingtone(getApplicationContext(), Variables.ringtoneUri); Variables.ringtoneTitle = ringtone.getTitle(getApplicationContext()); btnNotification.setText(Variables.ringtoneTitle); } break; } case APPSELECTED: { Log.i(TAG, Variables.appName); if (resultCode == RESULT_OK) { btnApp.setText(Variables.appName); } } } }
@Override public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); if (preference instanceof ListPreference) { ListPreference listPreference = (ListPreference) preference; int index = listPreference.findIndexOfValue(stringValue); preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null); } else if (preference instanceof RingtonePreference) { if (TextUtils.isEmpty(stringValue)) { preference.setSummary(R.string.pref_ringtone_silent); } else { Ringtone ringtone = RingtoneManager.getRingtone(preference.getContext(), Uri.parse(stringValue)); if (ringtone == null) { preference.setSummary(null); } else { String name = ringtone.getTitle(preference.getContext()); preference.setSummary(name); } } } else { preference.setSummary(stringValue); } return true; }
@Override public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); if (preference instanceof RingtonePreference) { // For ringtone preferences, look up the correct display value // using RingtoneManager. Ringtone ringtone = RingtoneManager.getRingtone(preference.getContext(), Uri.parse(stringValue)); if (ringtone == null) { // Clear the summary if there was a lookup error. preference.setSummary(null); } else { // Set the summary to reflect the new ringtone display // name. String name = ringtone.getTitle(preference.getContext()); preference.setSummary(name); } } else { // For all other preferences, set the summary to the value's // simple string representation. preference.setSummary(stringValue); } return true; }
private void playSounds(boolean locked) { // User feedback for keyguard. if (mSuppressNextLockSound) { mSuppressNextLockSound = false; return; } final ContentResolver cr = mContext.getContentResolver(); if (Settings.System.getInt(cr, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) == 1) { final String whichSound = locked ? Settings.System.LOCK_SOUND : Settings.System.UNLOCK_SOUND; final String soundPath = Settings.System.getString(cr, whichSound); if (soundPath != null) { final Uri soundUri = Uri.parse("file://" + soundPath); if (soundUri != null) { final Ringtone sfx = RingtoneManager.getRingtone(mContext, soundUri); if (sfx != null) { sfx.setStreamType(AudioManager.STREAM_SYSTEM); sfx.play(); } else { Log.d(TAG, "playSounds: failed to load ringtone from uri: " + soundUri); } } else { Log.d(TAG, "playSounds: could not parse Uri: " + soundPath); } } else { Log.d(TAG, "playSounds: whichSound = " + whichSound + "; soundPath was null"); } } }
public void setLBAlarm(Alarm alarm) { this.alarm = alarm; preferences.clear(); preferences.add( new AlarmPre( AlarmPre.Key.ALARM_ACTIVE, "Active", null, null, alarm.getAlarmActive(), Type.BOOLEAN)); preferences.add( new AlarmPre( AlarmPre.Key.ALARM_NAME, "Detail", alarm.getAlarmName(), null, alarm.getAlarmName(), Type.STRING)); preferences.add( new AlarmPre( AlarmPre.Key.ALARM_TIME, "Time", alarm.getAlarmTimeString(), null, alarm.getAlarmTime(), Type.TIME)); preferences.add( new AlarmPre( AlarmPre.Key.ALARM_REPEAT, "Repeat", alarm.getRepeatDaysString(), repeatDays, alarm.getDays(), Type.MULTIPLE_LIST)); Uri alarmToneUri = Uri.parse(alarm.getAlarmTonePath()); Ringtone alarmTone = RingtoneManager.getRingtone(getContext(), alarmToneUri); if (alarmTone instanceof Ringtone && !alarm.getAlarmTonePath().equalsIgnoreCase("")) { preferences.add( new AlarmPre( AlarmPre.Key.ALARM_TONE, "Ringtone", alarmTone.getTitle(getContext()), alarmTones, alarm.getAlarmTonePath(), Type.LIST)); } else { preferences.add( new AlarmPre( AlarmPre.Key.ALARM_TONE, "Ringtone", getAlarmTones()[0], alarmTones, null, Type.LIST)); } preferences.add( new AlarmPre( AlarmPre.Key.ALARM_VIBRATE, "Vibrate", null, null, alarm.getVibrate(), Type.BOOLEAN)); }
/** Plays a sound notification to alert the user. */ public void playNotification() { try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); } catch (Exception e) { } }
private void AlertNotify() { try { Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(ApplicationContextProvider.getContext(), sound); r.play(); } catch (Exception e) { } }
private void sonar() { try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); } catch (Exception e) { e.printStackTrace(); } }
public static void playNotificationSound(Context context) { try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(context, notification); r.play(); } catch (Exception e) { e.printStackTrace(); } }
@Override public boolean onPreferenceChange(Preference preference, Object value) { // Do not bind toggles. if (preference instanceof CheckBoxPreference || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && preference instanceof TwoStatePreference)) { return true; } String stringValue = value.toString(); if (preference instanceof ListPreference) { // For list preferences, look up the correct display value in // the preference's 'entries' list. ListPreference listPreference = (ListPreference) preference; int index = listPreference.findIndexOfValue(stringValue); // Set the summary to reflect the new value. preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null); } else if (preference instanceof RingtonePreference) { // For ringtone preferences, look up the correct display value // using RingtoneManager. if (TextUtils.isEmpty(stringValue)) { // Empty values correspond to 'silent' (no ringtone). preference.setSummary(R.string.ringtone_silent); } else { Ringtone ringtone = RingtoneManager.getRingtone(preference.getContext(), Uri.parse(stringValue)); if (ringtone == null) { // Clear the summary if there was a lookup error. preference.setSummary(null); } else { // Set the summary to reflect the new ringtone display // name. String name = ringtone.getTitle(preference.getContext()); preference.setSummary(name); } } } else if (preference instanceof EditTextPreference) { EditTextPreference textPreference = (EditTextPreference) preference; int inputType = textPreference.getEditText().getInputType(); if (inputType == (InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD)) { preference.setSummary(stringValue.replaceAll(".", "*")); } else { preference.setSummary(stringValue); } } else { // For all other preferences, set the summary to the value's // simple string representation. preference.setSummary(stringValue); } return true; }
private void setSummaryFromValue(Uri ringtoneUri) { if (ringtoneUri == null) { setSummary(R.string._title_silent); return; } final Context c = getContext(); final Ringtone r = RingtoneManager.getRingtone(c, ringtoneUri); setSummary(r == null ? null : r.getTitle(c)); }
private void updateRingtoneSummary(RingtonePreference preference, String uri) { Uri ringtoneUri = Uri.parse((String) uri); Ringtone ringtone = RingtoneManager.getRingtone(this, ringtoneUri); if (ringtone != null) { preference.setSummary(ringtone.getTitle(this)); } else { preference.setSummary("Silent"); } onContentChanged(); }
public static void playNotificationSound(Context context) { Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (uri != null) { Ringtone rt = RingtoneManager.getRingtone(context, uri); if (rt != null) { rt.setStreamType(AudioManager.STREAM_NOTIFICATION); rt.play(); } } }
@Override protected void onDestroy() { super.onDestroy(); if (soundPool != null) soundPool.release(); if (ringtone != null && ringtone.isPlaying()) ringtone.stop(); audioManager.setMode(AudioManager.MODE_NORMAL); audioManager.setMicrophoneMute(false); if (callStateListener != null) EMChatManager.getInstance().removeCallStateChangeListener(callStateListener); }
public String getRingtoneTitleFromUri(Context context, String uri) { if (TextUtils.isEmpty(uri)) { return null; } Ringtone ring = RingtoneManager.getRingtone(getActivity(), Uri.parse(uri)); if (ring != null) { return ring.getTitle(context); } return null; }
/** * Does a read-through cache for ringtone titles. * * @param uri The uri of the ringtone. * @return The ringtone title. {@literal null} if no matching ringtone found. */ private String getRingToneTitle(Uri uri) { // Try the cache first String title = mRingtoneTitleCache.getString(uri.toString()); if (title == null) { // This is slow because a media player is created during Ringtone object creation. Ringtone ringTone = RingtoneManager.getRingtone(mContext, uri); title = ringTone.getTitle(mContext); if (title != null) { mRingtoneTitleCache.putString(uri.toString(), title); } } return title; }
private void setRingtoneSummary() { Preference ringtone_preference = findPreference(PrefUtils.NOTIFICATIONS_RINGTONE); Uri ringtoneUri = Uri.parse(PrefUtils.getString(PrefUtils.NOTIFICATIONS_RINGTONE, "")); if (TextUtils.isEmpty(ringtoneUri.toString())) { ringtone_preference.setSummary(R.string.settings_notifications_ringtone_none); } else { Ringtone ringtone = RingtoneManager.getRingtone(MainApplication.getContext(), ringtoneUri); if (ringtone == null) { ringtone_preference.setSummary(R.string.settings_notifications_ringtone_none); } else { ringtone_preference.setSummary(ringtone.getTitle(MainApplication.getContext())); } } }
@Override public boolean onPreferenceChange(Preference preference, Object newValue) { String value = (String) newValue; if (TextUtils.isEmpty(value)) { preference.setSummary(R.string.preferences__silent); } else { Ringtone tone = RingtoneManager.getRingtone(getActivity(), Uri.parse(value)); if (tone != null) { preference.setSummary(tone.getTitle(getActivity())); } } return true; }
// Playing notification sound public void playNotificationSound() { try { Uri alarmSound = Uri.parse( ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + IsmartApp.getInstance().getApplicationContext().getPackageName() + "/raw/notification"); Ringtone r = RingtoneManager.getRingtone(IsmartApp.getInstance().getApplicationContext(), alarmSound); r.play(); } catch (Exception e) { e.printStackTrace(); } }
private void updateRingtonePreferenceSummary(String ringtoneUrl) { if (ringtoneUrl != null && ringtoneUrl.trim().equals("")) { ringTonePreference.setSummary("Silent"); return; } Uri ringtoneUri = Uri.parse(ringtoneUrl); Ringtone ringtone = RingtoneManager.getRingtone(this, ringtoneUri); String title = null; if (ringtone != null) { title = ringtone.getTitle(this); } ringTonePreference.setSummary(title); }
@Override protected void onResume() { if (preferencias != null) { // Escribo las preferencias en el TextView. StringBuilder sb = new StringBuilder(""); sb.append(getString(R.string.sincronizar)) .append(": ") .append(preferencias.getBoolean("prefSincronizar", false)) .append("\n"); sb.append(getString(R.string.tipo_conexion)) .append(": ") .append( preferencias.getString("prefTipoConexion", getString(R.string.tipo_conexion_default))) .append("\n"); sb.append(getString(R.string.letras_grandes)) .append(": ") .append(preferencias.getBoolean("prefLetrasGrandes", false)) .append("\n"); sb.append(getString(R.string.turnos)).append(":\n"); Set<String> turnosSeleccionados = preferencias.getStringSet("prefTurnos", null); if (turnosSeleccionados != null) { String[] turnos = new String[turnosSeleccionados.size()]; turnosSeleccionados.toArray(turnos); for (String turno : turnos) { sb.append(turno).append("\n"); } } sb.append(getString(R.string.lema)) .append(": ") .append(preferencias.getString("prefLema", "")) .append("\n"); sb.append(getString(R.string.tono_notificacion)).append(": "); String pathTono = preferencias.getString("prefTonoNotificacion", ""); Uri uriTono = Uri.parse(pathTono); Ringtone tono = RingtoneManager.getRingtone(this, uriTono); String nombreTono = tono.getTitle(this); sb.append(nombreTono).append("\n"); sb.append(getString(R.string.red)) .append(": ") .append(preferencias.getBoolean("prefRed", false)) .append("\n"); lblPreferencias.setText(sb.toString()); } super.onResume(); }
@Override public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); if (preference instanceof ListPreference) { // For list preferences, look up the correct display value in // the preference's 'entries' list. ListPreference listPreference = (ListPreference) preference; int index = listPreference.findIndexOfValue(stringValue); // Set the summary to reflect the new value. preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null); } else if (preference instanceof RingtonePreference) { // For ringtone preferences, look up the correct display value // using RingtoneManager. if (TextUtils.isEmpty(stringValue)) { // Empty values correspond to 'silent' (no ringtone). preference.setSummary(R.string.pref_ringtone_silent); } else { Ringtone ringtone = RingtoneManager.getRingtone(preference.getContext(), Uri.parse(stringValue)); if (ringtone == null) { // Clear the summary if there was a lookup error. preference.setSummary(null); } else { // Set the summary to reflect the new ringtone display // name. String name = ringtone.getTitle(preference.getContext()); preference.setSummary(name); } } } else if (preference instanceof EditTextPreference) { // For all other preferences, set the summary to the value's // simple string representation. preference.setSummary(stringValue); } else { preference.setSummary(stringValue); } return true; }
public String shortPath(String path) { if (isPathRingtone(mContext, path)) { Ringtone ringtone = RingtoneManager.getRingtone(mContext, Uri.parse(path)); // Just verified that the ringtone exists... not checking for null return ringtone.getTitle(mContext); } if (path == null) { return ""; } if (path.length() == 0) { return "xDrip Default"; } String[] segments = path.split("/"); if (segments.length > 1) { return segments[segments.length - 1]; } return path; }
@Override public void onReceive(Context context, Intent intent) { // here you can get the extras you passed in when creating the alarm // intent.getBundleExtra(REMINDER_BUNDLE)); try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(context, notification); r.play(); } catch (Exception e) { } Intent stop = new Intent(context, BusStopActivity.class); stop.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); stop.putExtras(intent.getExtras()); context.startActivity(stop); }
private void createNoifications(int icon, String endereco) { try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); mBuilder = new NotificationCompat.Builder(TelaMaps.this) .setSmallIcon(icon) .setContentTitle("Dormi No Ponto") .setContentText(endereco); mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(0, mBuilder.build()); } catch (Exception e) { Log.e("ERROR", "" + e.getMessage()); } }
@SuppressWarnings("deprecation") public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); int notifID; NotificationManager nm; // Get the notification ID notifID = getIntent().getExtras().getInt("NotifID"); // Create the pending intent that will reference the intent to go when clicked Intent i = new Intent(this, MainActivity.class); i.putExtra("NotifID", notifID); PendingIntent detailsIntent = PendingIntent.getActivity(this, 0, i, 0); // Setup notification nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification notif = new Notification(R.drawable.ic_launcher, "Food has expired!", System.currentTimeMillis()); // Hides status bar notification when clicked notif.flags |= Notification.FLAG_AUTO_CANCEL; CharSequence from = "RemindMe"; CharSequence message = "Food has expired!"; notif.setLatestEventInfo(this, from, message, detailsIntent); // ---100ms delay, vibrate for 250ms, pause for 100 ms and // then vibrate for 500ms--- notif.vibrate = new long[] {100, 250, 100, 500}; nm.notify(notifID, notif); // Added sound to notification try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); // this.setVolumeControlStream(AudioManager.STREAM_NOTIFICATION); r.setStreamType(AudioManager.STREAM_NOTIFICATION); r.play(); } catch (Exception e) { } // Destroy activity finish(); }
private void setPowerNotificationRingtone(Intent intent) { final Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); final String toneName; final String toneUriPath; if (uri != null) { final Ringtone ringtone = RingtoneManager.getRingtone(getActivity(), uri); toneName = ringtone.getTitle(getActivity()); toneUriPath = uri.toString(); } else { // silent toneName = getString(R.string.power_notifications_ringtone_silent); toneUriPath = POWER_NOTIFICATIONS_SILENT_URI; } mPowerSoundsRingtone.setSummary(toneName); Settings.Global.putString( getContentResolver(), Settings.Global.POWER_NOTIFICATIONS_RINGTONE, toneUriPath); }
@Override public void onReceive(Context context, Intent intent) { boolean iscloud = intent.getBooleanExtra("taskValue", false); if (iscloud) { String status = intent.getStringExtra("taskStatusValue"); selectedImage = intent.getStringExtra("selectedImage"); changeTaskStatus(status); } try { Uri notification = android.media.RingtoneManager.getDefaultUri( android.media.RingtoneManager.TYPE_NOTIFICATION); android.media.Ringtone r = android.media.RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); } catch (Exception e) { } }
public void run() { try { if (notification == null) { notification = RingtoneManager.getRingtone(ctx, RingtoneManager.getDefaultUri(type)); } if (notification != null) { notification.play(); } } catch (Exception e) { Log.e(LCAT, "Error playing beep.", e); } }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK) { Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); String name = null; if (ringtone != null && parentActivity != null) { Ringtone rng = RingtoneManager.getRingtone(parentActivity, ringtone); if (rng != null) { name = rng.getTitle(parentActivity); rng.stop(); } } SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); if (requestCode == 4) { if (name != null && ringtone != null) { editor.putString("GlobalSound", name); editor.putString("GlobalSoundPath", ringtone.toString()); } else { editor.putString("GlobalSound", "NoSound"); editor.putString("GlobalSoundPath", "NoSound"); } } else if (requestCode == 9) { if (name != null && ringtone != null) { editor.putString("GroupSound", name); editor.putString("GroupSoundPath", ringtone.toString()); } else { editor.putString("GroupSound", "NoSound"); editor.putString("GroupSoundPath", "NoSound"); } } editor.commit(); listView.invalidateViews(); } }