Java Code Examples for android.media.RingtoneManager#TYPE_ALARM
The following examples show how to use
android.media.RingtoneManager#TYPE_ALARM .
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: AlarmClockActivity.java From SuntimesWidget with GNU General Public License v3.0 | 6 votes |
protected void ringtonePicker(@NonNull AlarmClockItem item) { int ringtoneType = RingtoneManager.TYPE_RINGTONE; if (!AlarmSettings.loadPrefAllRingtones(this)) { ringtoneType = (item.type == AlarmClockItem.AlarmType.NOTIFICATION ? RingtoneManager.TYPE_NOTIFICATION : RingtoneManager.TYPE_ALARM); } Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, ringtoneType); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, item.type.getDisplayString()); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, AlarmSettings.getDefaultRingtoneUri(this, item.type)); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (item.ringtoneURI != null ? Uri.parse(item.ringtoneURI) : null)); t_selectedItem = item.rowID; startActivityForResult(intent, REQUEST_RINGTONE); }
Example 2
Source File: RingtonePickerActivity.java From ticdesign with Apache License 2.0 | 5 votes |
private int addDefaultRingtoneItem(TicklableRecyclerView listView) { if (mType == RingtoneManager.TYPE_NOTIFICATION) { return addStaticItem(listView, R.string.notification_sound_default); } else if (mType == RingtoneManager.TYPE_ALARM) { return addStaticItem(listView, R.string.alarm_sound_default); } return addStaticItem(listView, R.string.ringtone_default); }
Example 3
Source File: RingtonePreference.java From Silence with GNU General Public License v3.0 | 5 votes |
/** * Returns the selected ringtone's title, or {@code null} if no ringtone is picked. * * @return The selected ringtone's title, or {@code null} if no ringtone is picked. */ public String getRingtoneTitle() { Context context = getContext(); ContentResolver cr = context.getContentResolver(); String[] projection = {MediaStore.MediaColumns.TITLE}; String ringtoneTitle = null; if (ringtoneUri != null) { int type = RingtoneManager.getDefaultType(ringtoneUri); switch (type) { case RingtoneManager.TYPE_ALL: case RingtoneManager.TYPE_RINGTONE: ringtoneTitle = context.getString(R.string.RingtonePreference_ringtone_default); break; case RingtoneManager.TYPE_ALARM: ringtoneTitle = context.getString(R.string.RingtonePreference_alarm_sound_default); break; case RingtoneManager.TYPE_NOTIFICATION: ringtoneTitle = context.getString(R.string.RingtonePreference_notification_sound_default); break; default: try { Cursor cursor = cr.query(ringtoneUri, projection, null, null, null); if (cursor != null) { if (cursor.moveToFirst()) { ringtoneTitle = cursor.getString(0); } cursor.close(); } } catch (Exception ignore) { } } } return ringtoneTitle; }
Example 4
Source File: RingtonePreferenceDialogFragmentCompat.java From Silence with GNU General Public License v3.0 | 5 votes |
private static String getDirForType(int type) { switch (type) { case RingtoneManager.TYPE_ALL: case RingtoneManager.TYPE_RINGTONE: return Environment.DIRECTORY_RINGTONES; case RingtoneManager.TYPE_NOTIFICATION: return Environment.DIRECTORY_NOTIFICATIONS; case RingtoneManager.TYPE_ALARM: return Environment.DIRECTORY_ALARMS; default: throw new IllegalArgumentException("Unsupported ringtone type: " + type); } }
Example 5
Source File: TonesHandler.java From PhoneProfilesPlus with Apache License 2.0 | 5 votes |
static String getToneName(Context context, @SuppressWarnings("SameParameterValue") int type, String _uri) { if ((type == RingtoneManager.TYPE_RINGTONE) && (_uri.isEmpty() || _uri.equals(RINGING_TONE_URI_NONE))) return context.getString(R.string.ringtone_preference_none); if ((type == RingtoneManager.TYPE_NOTIFICATION) && (_uri.isEmpty() || _uri.equals(NOTIFICATION_TONE_URI_NONE))) return context.getString(R.string.ringtone_preference_none); if ((type == RingtoneManager.TYPE_ALARM) && (_uri.isEmpty() || _uri.equals(ALARM_TONE_URI_NONE))) return context.getString(R.string.ringtone_preference_none); RingtoneManager manager = new RingtoneManager(context); manager.setType(type); Cursor cursor = manager.getCursor(); //PPApplication.logE("TonesHandler.getToneName", "_uri="+_uri); while (cursor.moveToNext()) { String id = cursor.getString(RingtoneManager.ID_COLUMN_INDEX); String uri = cursor.getString(RingtoneManager.URI_COLUMN_INDEX); String title = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX); String uriId = uri + "/" + id; //Log.d("TonesHandler.getToneName", "title="+title); //Log.d("TonesHandler.getToneName", "uriId="+uriId); if (uriId.equals(_uri)) return title; } return ""; }
Example 6
Source File: RingtonePreferenceDialogFragmentCompat.java From Silence with GNU General Public License v3.0 | 4 votes |
@NonNull private Cursor createCursor(Uri ringtoneUri) { RingtonePreference ringtonePreference = getRingtonePreference(); ringtoneManager = new RingtoneManager(getContext()); ringtoneManager.setType(ringtonePreference.getRingtoneType()); ringtoneManager.setStopPreviousRingtone(true); Cursor ringtoneCursor = ringtoneManager.getCursor(); String colId = ringtoneCursor.getColumnName(RingtoneManager.ID_COLUMN_INDEX); String colTitle = ringtoneCursor.getColumnName(RingtoneManager.TITLE_COLUMN_INDEX); MatrixCursor extras = new MatrixCursor(new String[]{colId, colTitle}); final int ringtoneType = ringtonePreference.getRingtoneType(); final boolean showDefault = ringtonePreference.getShowDefault(); final boolean showSilent = ringtonePreference.getShowSilent(); if (showDefault) { switch (ringtoneType) { case RingtoneManager.TYPE_ALARM: extras.addRow(new String[]{CURSOR_DEFAULT_ID, getString(R.string.RingtonePreference_alarm_sound_default)}); break; case RingtoneManager.TYPE_NOTIFICATION: extras.addRow(new String[]{CURSOR_DEFAULT_ID, getString(R.string.RingtonePreference_notification_sound_default)}); break; case RingtoneManager.TYPE_RINGTONE: case RingtoneManager.TYPE_ALL: default: extras.addRow(new String[]{CURSOR_DEFAULT_ID, getString(R.string.RingtonePreference_ringtone_default)}); break; } } if (showSilent) { extras.addRow(new String[]{CURSOR_NONE_ID, getString(R.string.RingtonePreference_ringtone_silent)}); } selectedIndex = ringtoneManager.getRingtonePosition(ringtoneUri); if (selectedIndex >= 0) { selectedIndex += (showDefault ? 1 : 0) + (showSilent ? 1 : 0); } if (selectedIndex < 0 && showDefault) { if (RingtoneManager.getDefaultType(ringtoneUri) != -1) { selectedIndex = 0; } } if (selectedIndex < 0 && showSilent) { selectedIndex = showDefault ? 1 : 0; } Cursor[] cursors = {extras, ringtoneCursor}; return this.cursor = new MergeCursor(cursors); }
Example 7
Source File: RingTools.java From Mp3Cutter with GNU General Public License v3.0 | votes |
private static void setRingHasPermission(Activity context, int type, String path) { Uri oldRingtoneUri = RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE); //系统当前 通知铃声 Uri oldNotification = RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_NOTIFICATION); //系统当前 通知铃声 Uri oldAlarm = RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_ALARM); //系统当前 闹钟铃声 File sdfile = new File(path); ContentValues values = new ContentValues(); values.put(MediaStore.MediaColumns.DATA, sdfile.getAbsolutePath()); values.put(MediaStore.MediaColumns.TITLE, sdfile.getName()); values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3"); values.put(MediaStore.Audio.Media.IS_RINGTONE, true); values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true); values.put(MediaStore.Audio.Media.IS_ALARM, true); values.put(MediaStore.Audio.Media.IS_MUSIC, true); Uri uri = MediaStore.Audio.Media.getContentUriForPath(sdfile.getAbsolutePath()); Uri newUri = null; String deleteId = ""; try { Cursor cursor = context.getContentResolver().query(uri, null, MediaStore.MediaColumns.DATA + "=?", new String[]{path}, null); if (cursor.moveToFirst()) { deleteId = cursor.getString(cursor.getColumnIndex("_id")); } Logger.d(" + deleteId" + deleteId); context.getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + sdfile.getAbsolutePath() + "\"", null); newUri = context.getContentResolver().insert(uri, values); } catch (Exception e) { e.printStackTrace(); } if (newUri != null) { String ringStoneId = ""; String notificationId = ""; String alarmId = ""; if (null != oldRingtoneUri) { ringStoneId = oldRingtoneUri.getLastPathSegment(); } if (null != oldNotification) { notificationId = oldNotification.getLastPathSegment(); } if (null != oldAlarm) { alarmId = oldAlarm.getLastPathSegment(); } Uri setRingStoneUri; Uri setNotificationUri; Uri setAlarmUri; if (type == RingtoneManager.TYPE_RINGTONE || ringStoneId.equals(deleteId)) { setRingStoneUri = newUri; } else { setRingStoneUri = oldRingtoneUri; } if (type == RingtoneManager.TYPE_NOTIFICATION || notificationId.equals(deleteId)) { setNotificationUri = newUri; } else { setNotificationUri = oldNotification; } if (type == RingtoneManager.TYPE_ALARM || alarmId.equals(deleteId)) { setAlarmUri = newUri; } else { setAlarmUri = oldAlarm; } RingtoneManager.setActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE, setRingStoneUri); RingtoneManager.setActualDefaultRingtoneUri(context, RingtoneManager.TYPE_NOTIFICATION, setNotificationUri); RingtoneManager.setActualDefaultRingtoneUri(context, RingtoneManager.TYPE_ALARM, setAlarmUri); switch (type) { case RingtoneManager.TYPE_RINGTONE: Toast.makeText(context.getApplicationContext(), "设置来电铃声成功!", Toast.LENGTH_SHORT).show(); break; case RingtoneManager.TYPE_NOTIFICATION: Toast.makeText(context.getApplicationContext(), "设置通知铃声成功!", Toast.LENGTH_SHORT).show(); break; case RingtoneManager.TYPE_ALARM: Toast.makeText(context.getApplicationContext(), "设置闹钟铃声成功!", Toast.LENGTH_SHORT).show(); break; } } }