android.media.Ringtone Java Examples
The following examples show how to use
android.media.Ringtone.
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: Notification.java From phonegapbootcampsite with MIT License | 6 votes |
/** * Beep plays the default notification ringtone. * * @param count Number of times to play notification */ public void beep(long count) { Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone notification = RingtoneManager.getRingtone(this.cordova.getActivity().getBaseContext(), ringtone); // If phone is not set to silent mode if (notification != null) { for (long i = 0; i < count; ++i) { notification.play(); long timeout = 5000; while (notification.isPlaying() && (timeout > 0)) { timeout = timeout - 100; try { Thread.sleep(100); } catch (InterruptedException e) { } } } } }
Example #2
Source File: AlarmScreenActivity.java From BaldPhone with Apache License 2.0 | 6 votes |
public static Ringtone getRingtone(Context context) { Uri alert = RingtoneManager .getActualDefaultRingtoneUri(context.getApplicationContext(), RingtoneManager.TYPE_ALARM); if (alert == null) alert = RingtoneManager .getActualDefaultRingtoneUri(context.getApplicationContext(), RingtoneManager.TYPE_NOTIFICATION); if (alert == null) alert = RingtoneManager .getActualDefaultRingtoneUri(context.getApplicationContext(), RingtoneManager.TYPE_RINGTONE); final Ringtone ringtone = RingtoneManager.getRingtone(context, alert); final AudioManager audioManager = (AudioManager) context.getSystemService(AUDIO_SERVICE); if (audioManager != null) {//who knows lol - btw don't delete user's may lower the alarm sounds by mistake final int alarmVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM) * (BPrefs.get(context).getInt(BPrefs.ALARM_VOLUME_KEY, BPrefs.ALARM_VOLUME_DEFAULT_VALUE) + 6) / 10; audioManager.setStreamVolume(AudioManager.STREAM_ALARM, alarmVolume, 0); } ringtone.setAudioAttributes(alarmAttributes); return ringtone; }
Example #3
Source File: Notification.java From reader with MIT License | 6 votes |
/** * Beep plays the default notification ringtone. * * @param count Number of times to play notification */ public void beep(final long count) { cordova.getThreadPool().execute(new Runnable() { public void run() { Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone notification = RingtoneManager.getRingtone(cordova.getActivity().getBaseContext(), ringtone); // If phone is not set to silent mode if (notification != null) { for (long i = 0; i < count; ++i) { notification.play(); long timeout = 5000; while (notification.isPlaying() && (timeout > 0)) { timeout = timeout - 100; try { Thread.sleep(100); } catch (InterruptedException e) { } } } } } }); }
Example #4
Source File: Notification.java From reader with MIT License | 6 votes |
/** * Beep plays the default notification ringtone. * * @param count Number of times to play notification */ public void beep(final long count) { cordova.getThreadPool().execute(new Runnable() { public void run() { Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone notification = RingtoneManager.getRingtone(cordova.getActivity().getBaseContext(), ringtone); // If phone is not set to silent mode if (notification != null) { for (long i = 0; i < count; ++i) { notification.play(); long timeout = 5000; while (notification.isPlaying() && (timeout > 0)) { timeout = timeout - 100; try { Thread.sleep(100); } catch (InterruptedException e) { } } } } } }); }
Example #5
Source File: SettingsFragment.java From sms-ticket with Apache License 2.0 | 6 votes |
private void updateRingtoneSummary(PreferenceScreen preferenceScreen) { String name = getString(R.string.pref_ringtone_none); String value = Preferences.getString(mContext, Preferences.NOTIFICATION_RINGTONE, null); if (!TextUtils.isEmpty(value)) { Uri ringtoneUri = Uri.parse(value); Ringtone ringtone = RingtoneManager.getRingtone(mContext, ringtoneUri); if (ringtone != null) { name = ringtone.getTitle(mContext); } } preferenceScreen.findPreference(Preferences.NOTIFICATION_RINGTONE).setSummary(name); preferenceScreen.findPreference(Preferences.NOTIFICATION_RINGTONE).setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { String v = (String) newValue; preference.setSummary(v); return true; } }); }
Example #6
Source File: EditAlertActivity.java From NightWatch with GNU General Public License v3.0 | 6 votes |
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; }
Example #7
Source File: Notification.java From reacteu-app with MIT License | 6 votes |
/** * Beep plays the default notification ringtone. * * @param count Number of times to play notification */ public void beep(final long count) { cordova.getThreadPool().execute(new Runnable() { public void run() { Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone notification = RingtoneManager.getRingtone(cordova.getActivity().getBaseContext(), ringtone); // If phone is not set to silent mode if (notification != null) { for (long i = 0; i < count; ++i) { notification.play(); long timeout = 5000; while (notification.isPlaying() && (timeout > 0)) { timeout = timeout - 100; try { Thread.sleep(100); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } } } } }); }
Example #8
Source File: AlertList.java From NightWatch with GNU General Public License v3.0 | 6 votes |
public String shortPath(String path) { if(path != null) { if(path.length() == 0) { return "xDrip Default"; } Ringtone ringtone = RingtoneManager.getRingtone(mContext, Uri.parse(path)); if (ringtone != null) { return ringtone.getTitle(mContext); } else { String[] segments = path.split("/"); if (segments.length > 1) { return segments[segments.length - 1]; } } } return ""; }
Example #9
Source File: NotificationFragment.java From iBeebo with GNU General Public License v3.0 | 6 votes |
private void buildSummary() { if (SettingUtils.getEnableFetchMSG()) { String value = PreferenceManager.getDefaultSharedPreferences(getActivity()).getString(SettingActivity.FREQUENCY, "1"); frequency.setSummary(getActivity().getResources().getStringArray(R.array.frequency)[Integer.valueOf(value) - 1]); } else { frequency.setSummary(getString(R.string.stopped)); } if (uri != null) { Ringtone r = RingtoneManager.getRingtone(getActivity(), uri); ringtone.setSummary(r.getTitle(getActivity())); } else { ringtone.setSummary(getString(R.string.silent)); } }
Example #10
Source File: AlertList.java From NightWatch with GNU General Public License v3.0 | 6 votes |
public String shortPath(String path) { if(path != null) { if(path.length() == 0) { return "xDrip Default"; } Ringtone ringtone = RingtoneManager.getRingtone(mContext, Uri.parse(path)); if (ringtone != null) { return ringtone.getTitle(mContext); } else { String[] segments = path.split("/"); if (segments.length > 1) { return segments[segments.length - 1]; } } } return ""; }
Example #11
Source File: AlertList.java From xDrip-Experimental with GNU General Public License v3.0 | 6 votes |
public String shortPath(String path) { if(path != null) { if(path.length() == 0) { return "xDrip Default"; } Ringtone ringtone = RingtoneManager.getRingtone(mContext, Uri.parse(path)); if (ringtone != null) { return ringtone.getTitle(mContext); } else { String[] segments = path.split("/"); if (segments.length > 1) { return segments[segments.length - 1]; } } } return ""; }
Example #12
Source File: AlarmSettingItemListAdapter.java From SpecialAlarmClock with Apache License 2.0 | 6 votes |
public void setMathAlarm(Alarm alarm) { this.alarm = alarm; preferences.clear(); // preferences.add(new AlarmPreference(Key.ALARM_ACTIVE, context.getString(R.string.AlarmStatus), null, null, alarm.getAlarmActive(), Type.BOOLEAN)); preferences.add(new AlarmPreference(Key.ALARM_NAME, "标签", alarm.getAlarmName(), null, alarm.getAlarmName(), Type.EditText)); preferences.add(new AlarmPreference(Key.ALARM_TIME, "时间", alarm.getAlarmTimeString(), null, alarm.getAlarmTime(), Type.TIME)); preferences.add(new AlarmPreference(Key.ALARM_REPEAT, "重复", "重复", repeatDays, alarm.getDays(), Type.MULTIPLE_ImageButton)); Uri alarmToneUri = Uri.parse(alarm.getAlarmTonePath()); Ringtone alarmTone = RingtoneManager.getRingtone(getContext(), alarmToneUri); if (alarmTone instanceof Ringtone && !alarm.getAlarmTonePath().equalsIgnoreCase("")) { preferences.add(new AlarmPreference(Key.ALARM_TONE, "铃声", alarmTone.getTitle(getContext()), alarmTones, alarm.getAlarmTonePath(), Type.Ring)); } else { preferences.add(new AlarmPreference(Key.ALARM_TONE, "铃声", getAlarmTones()[0], alarmTones, null, Type.Ring)); } preferences.add(new AlarmPreference(Key.ALARM_VIBRATE, "振动", null, null, alarm.IsVibrate(), Type.BOOLEAN)); }
Example #13
Source File: AlertList.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
private String shortPath(String path) { try { if (path != null) { if (path.length() == 0) { return "xDrip Default"; } Ringtone ringtone = RingtoneManager.getRingtone(mContext, Uri.parse(path)); if (ringtone != null) { return ringtone.getTitle(mContext); } else { String[] segments = path.split("/"); if (segments.length > 1) { return segments[segments.length - 1]; } } } return ""; } catch (SecurityException e) { // need external storage permission? checkStoragePermissions(gs(R.string.need_permission_to_access_audio_files)); return ""; } }
Example #14
Source File: Notification.java From showCaseCordova with Apache License 2.0 | 6 votes |
/** * Beep plays the default notification ringtone. * * @param count Number of times to play notification */ public void beep(final long count) { cordova.getThreadPool().execute(new Runnable() { public void run() { Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone notification = RingtoneManager.getRingtone(cordova.getActivity().getBaseContext(), ringtone); // If phone is not set to silent mode if (notification != null) { for (long i = 0; i < count; ++i) { notification.play(); long timeout = 5000; while (notification.isPlaying() && (timeout > 0)) { timeout = timeout - 100; try { Thread.sleep(100); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } } } } }); }
Example #15
Source File: MainActivity.java From WechatUnrecalled with GNU General Public License v3.0 | 6 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK) { Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); Ringtone ringTone = RingtoneManager.getRingtone(getApplicationContext(), uri); ringtone_name.setText(ringTone.getTitle(this)); switch (requestCode) { case REQUEST_TONE_PICKER_CUSTOM: mSettingsHelper.setString("custom_ringtone", uri.toString()); break; case REQUEST_TONE_PICKER_NEW_COMMENT: mSettingsHelper.setString("new_comment_ringtone", uri.toString()); break; case REQUEST_TONE_PICKER_MSG_RECALL: mSettingsHelper.setString("msg_recall_ringtone", uri.toString()); break; case REQUEST_TONE_PICKER_COMMENT_RECALL: mSettingsHelper.setString("comment_recall_ringtone", uri.toString()); break; } } }
Example #16
Source File: NotificationsPreferenceFragment.java From deltachat-android with GNU General Public License v3.0 | 6 votes |
@Override public boolean onPreferenceChange(Preference preference, Object newValue) { Uri value = (Uri) newValue; if (value == null || TextUtils.isEmpty(value.toString())) { preference.setSummary(R.string.pref_silent); } else { Ringtone tone = RingtoneManager.getRingtone(getActivity(), value); if (tone != null) { preference.setSummary(tone.getTitle(getActivity())); } } return true; }
Example #17
Source File: Notification.java From jpHolo with MIT License | 6 votes |
/** * Beep plays the default notification ringtone. * * @param count Number of times to play notification */ public void beep(final long count) { cordova.getThreadPool().execute(new Runnable() { public void run() { Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone notification = RingtoneManager.getRingtone(cordova.getActivity().getBaseContext(), ringtone); // If phone is not set to silent mode if (notification != null) { for (long i = 0; i < count; ++i) { notification.play(); long timeout = 5000; while (notification.isPlaying() && (timeout > 0)) { timeout = timeout - 100; try { Thread.sleep(100); } catch (InterruptedException e) { } } } } } }); }
Example #18
Source File: RingtoneUtils.java From android-ringtone-picker with Apache License 2.0 | 6 votes |
/** * Get the title of the ringtone from the uri of ringtone. * * @param context instance of the caller * @param uri uri of the tone to search * @return title of the tone or return null if no tone found. */ @Nullable public static String getRingtoneName(@NonNull final Context context, @NonNull final Uri uri) { final Ringtone ringtone = RingtoneManager.getRingtone(context, uri); if (ringtone != null) { return ringtone.getTitle(context); } else { Cursor cur = context .getContentResolver() .query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, new String[]{MediaStore.Audio.Media.TITLE}, MediaStore.Audio.Media._ID + " =?", new String[]{uri.getLastPathSegment()}, null); String title = null; if (cur != null) { title = cur.getString(cur.getColumnIndex(MediaStore.Audio.Media.TITLE)); cur.close(); } return title; } }
Example #19
Source File: PreferencesFragmentSummary.java From AndroidBlueprints with Apache License 2.0 | 5 votes |
@Override public boolean onPreferenceChange(Preference pref, Object newValue) { if (newValue != null && newValue instanceof String) { String uri = (String) newValue; Ringtone ringtone = RingtoneManager.getRingtone(pref.getContext(), Uri.parse(uri)); pref.setSummary(ringtone.getTitle(pref.getContext())); } return true; }
Example #20
Source File: AudioVideoRingtoneManagerActivity.java From coursera-android with MIT License | 5 votes |
private void playRingtone(Ringtone newRingtone) { if (null != mCurrentRingtone && mCurrentRingtone.isPlaying()) mCurrentRingtone.stop(); mCurrentRingtone = newRingtone; if (null != newRingtone) { mCurrentRingtone.play(); } }
Example #21
Source File: EditAlertActivity.java From NightWatch with GNU General Public License v3.0 | 5 votes |
public static boolean isPathRingtone(Context context, String path) { if(path == null) { return false; } if(path.length() == 0) { return false; } Ringtone ringtone = RingtoneManager.getRingtone(context, Uri.parse(path)); if(ringtone == null) { return false; } return true; }
Example #22
Source File: ActivitySetup.java From FairEmail with GNU General Public License v3.0 | 5 votes |
@RequiresApi(api = Build.VERSION_CODES.O) static NotificationChannel channelFromJSON(Context context, JSONObject jchannel) throws JSONException { NotificationChannel channel = new NotificationChannel( jchannel.getString("id"), jchannel.getString("name"), jchannel.getInt("importance")); String group = jchannel.optString("group"); if (!TextUtils.isEmpty(group)) channel.setGroup(group); if (jchannel.has("description") && !jchannel.isNull("description")) channel.setDescription(jchannel.getString("description")); channel.setBypassDnd(jchannel.getBoolean("dnd")); channel.setLockscreenVisibility(jchannel.getInt("visibility")); channel.setShowBadge(jchannel.getBoolean("badge")); if (jchannel.has("sound") && !jchannel.isNull("sound")) { Uri uri = Uri.parse(jchannel.getString("sound")); Ringtone ringtone = RingtoneManager.getRingtone(context, uri); if (ringtone != null) channel.setSound(uri, Notification.AUDIO_ATTRIBUTES_DEFAULT); } channel.enableLights(jchannel.getBoolean("light")); channel.enableVibration(jchannel.getBoolean("vibrate")); return channel; }
Example #23
Source File: ActivitySettings.java From EasySettings with Apache License 2.0 | 5 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE_NOTIFICATION_PICKER && resultCode == RESULT_OK) { Uri notificationToneUri = (Uri) data.getExtras().get(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); //todo save the value to shared preferences EasySettings.retrieveSettingsSharedPrefs(this) .edit() .putString(ActivityMain.SETTINGS_KEY_RINGTONE, //if notificationToneUri is null, it means "silent" //was chosen. notificationToneUri == null ? SETTINGS_RINGTONE_SILENT_VALUE : notificationToneUri.toString()) .apply(); String soundTitle; //"silent" was chosen if(notificationToneUri == null) { soundTitle = DEFAULT_NOTIFICATION_SUMMARY; } else { Ringtone ringtone = RingtoneManager.getRingtone(this, notificationToneUri); soundTitle = ringtone.getTitle(this); } if(tvNotificationToneSummary != null) { tvNotificationToneSummary.setText(soundTitle); } } }
Example #24
Source File: Conversions.java From boilr with GNU General Public License v3.0 | 5 votes |
public static String ringtoneUriToName(String stringUri, Context context) { if(stringUri.equals("")) return context.getString(R.string.silent); Uri uri = Uri.parse(stringUri); // Context context = activity.getApplicationContext(); Ringtone ringtone = RingtoneManager.getRingtone(context, uri); return ringtone != null ? ringtone.getTitle(context) : context.getString(R.string.unknown_ringtone); }
Example #25
Source File: NotificationService.java From Ecommerce-Retronight-Android with Creative Commons Zero v1.0 Universal | 5 votes |
public void showNotification(String msg) { int stringId = getApplicationContext().getApplicationInfo().labelRes; String appName = getApplicationContext().getString(stringId); mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Intent newIntent = new Intent(this, SplashActivity.class); newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, newIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle(msg) .setDefaults(Notification.DEFAULT_ALL) .setStyle(new NotificationCompat.BigTextStyle() .bigText(msg)) .setContentText("New updates for " + appName); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); }
Example #26
Source File: SettingsActivity.java From Android-Audio-Recorder with Apache License 2.0 | 5 votes |
@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. 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; }
Example #27
Source File: Toast.java From RobotHelper with GNU Affero General Public License v3.0 | 5 votes |
/** * 声音提示 */ public static void notice() { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(MainApplication.getInstance(), notification); r.play(); Vibrator vibrator = (Vibrator) MainApplication.getInstance().getSystemService(VIBRATOR_SERVICE); vibrator.vibrate(1000); }
Example #28
Source File: Preferences.java From xDrip with GNU General Public License v3.0 | 5 votes |
@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) { // 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 { // For all other preferences, set the summary to the value's // simple string representation. preference.setSummary(stringValue); } return true; }
Example #29
Source File: EditAlertActivity.java From xDrip with GNU General Public License v3.0 | 5 votes |
public static boolean isPathRingtone(Context context, String path) { if (path == null || path.isEmpty()) { return false; } Ringtone ringtone = RingtoneManager.getRingtone(context, Uri.parse(path)); return ringtone != null; }
Example #30
Source File: SettingsActivity.java From xDrip with GNU General Public License v3.0 | 5 votes |
@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; }