Java Code Examples for android.media.RingtoneManager#setType()
The following examples show how to use
android.media.RingtoneManager#setType() .
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: RingtoneSoundChooserFragment.java From Alarmio with Apache License 2.0 | 6 votes |
@Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_sound_chooser_list, container, false); RecyclerView recyclerView = view.findViewById(R.id.recycler); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); List<SoundData> sounds = new ArrayList<>(); RingtoneManager manager = new RingtoneManager(getContext()); manager.setType(RingtoneManager.TYPE_RINGTONE); Cursor cursor = manager.getCursor(); int count = cursor.getCount(); if (count > 0 && cursor.moveToFirst()) { do { sounds.add(new SoundData(cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX), SoundData.TYPE_RINGTONE, cursor.getString(RingtoneManager.URI_COLUMN_INDEX) + "/" + cursor.getString(RingtoneManager.ID_COLUMN_INDEX))); } while (cursor.moveToNext()); } SoundsAdapter adapter = new SoundsAdapter(getAlarmio(), sounds); adapter.setListener(this); recyclerView.setAdapter(adapter); return view; }
Example 2
Source File: AlarmSoundChooserFragment.java From Alarmio with Apache License 2.0 | 6 votes |
@Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_sound_chooser_list, container, false); RecyclerView recyclerView = view.findViewById(R.id.recycler); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); List<SoundData> sounds = new ArrayList<>(); RingtoneManager manager = new RingtoneManager(getContext()); manager.setType(RingtoneManager.TYPE_ALARM); Cursor cursor = manager.getCursor(); int count = cursor.getCount(); if (count > 0 && cursor.moveToFirst()) { do { sounds.add(new SoundData(cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX), SoundData.TYPE_RINGTONE, cursor.getString(RingtoneManager.URI_COLUMN_INDEX) + "/" + cursor.getString(RingtoneManager.ID_COLUMN_INDEX))); } while (cursor.moveToNext()); } SoundsAdapter adapter = new SoundsAdapter(getAlarmio(), sounds); adapter.setListener(this); recyclerView.setAdapter(adapter); return view; }
Example 3
Source File: AlertPlugin.java From microbit with Apache License 2.0 | 6 votes |
private Uri searchAlarmUri(int alarmId) { Context context = MBApp.getApp(); RingtoneManager ringtoneMgr = new RingtoneManager(context); ringtoneMgr.setType(RingtoneManager.TYPE_ALARM); Cursor alarms = ringtoneMgr.getCursor(); Log.i(TAG, "playAlarm: total alarms = " + alarms.getCount()); alarms.moveToPosition(alarmId - 4); Uri alarm = ringtoneMgr.getRingtoneUri(alarms.getPosition()); if(alarm == null) { Log.i(TAG, "Cannot play nth Alarm. Playing default"); alarm = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); } return alarm; }
Example 4
Source File: RingtoneUtils.java From android-ringtone-picker with Apache License 2.0 | 6 votes |
/** * Get the tone from {@link RingtoneManager} for any given type. It will add title as the key and * uri of the sound as value in given {@link LinkedHashMap}. * * @param context instance of the caller * @param type type of the ringtone from {@link RingtonePickerDialog.Builder#TYPE_NOTIFICATION}, * {@link RingtonePickerDialog.Builder#TYPE_RINGTONE} or * {@link RingtonePickerDialog.Builder#TYPE_ALARM}. * @return {@link LinkedHashMap} of the title-{@link Uri} pair of all the ringtone of given type. */ @CheckResult @NonNull private static LinkedHashMap<String, Uri> getTone(@NonNull final Context context, final int type) { final LinkedHashMap<String, Uri> ringToneList = new LinkedHashMap<>(); final RingtoneManager ringtoneManager = new RingtoneManager(context); ringtoneManager.setType(type); final Cursor ringsCursor = ringtoneManager.getCursor(); while (ringsCursor.moveToNext()) { ringToneList.put(ringsCursor.getString(RingtoneManager.TITLE_COLUMN_INDEX), Uri.parse(ringsCursor.getString(RingtoneManager.URI_COLUMN_INDEX) + "/" + ringsCursor.getString(RingtoneManager.ID_COLUMN_INDEX))); } ringsCursor.close(); return ringToneList; }
Example 5
Source File: AlarmSettingItemListAdapter.java From SpecialAlarmClock with Apache License 2.0 | 6 votes |
public AlarmSettingItemListAdapter(Context context, Alarm alarm) { this.context = (context); Log.d("AlarmSettingItemListAdapter", "Loading Ringtones..."); RingtoneManager ringtoneMgr = new RingtoneManager(getContext()); ringtoneMgr.setType(RingtoneManager.TYPE_ALARM); Cursor alarmsCursor = ringtoneMgr.getCursor(); alarmTones = new String[alarmsCursor.getCount() + 1]; alarmTones[0] = "静默模式"; alarmTonePaths = new String[alarmsCursor.getCount() + 1]; alarmTonePaths[0] = ""; if (alarmsCursor.moveToFirst()) { do { Log.d("ITEM", ringtoneMgr.getRingtone(alarmsCursor.getPosition()).getTitle(getContext())); Log.d("ITEM", ringtoneMgr.getRingtoneUri(alarmsCursor.getPosition()).toString()); alarmTones[alarmsCursor.getPosition() + 1] = ringtoneMgr.getRingtone(alarmsCursor.getPosition()).getTitle(getContext()); alarmTonePaths[alarmsCursor.getPosition() + 1] = ringtoneMgr.getRingtoneUri(alarmsCursor.getPosition()).toString(); } while (alarmsCursor.moveToNext()); } Log.d("AlarmSettingItemListAdapter", "Finished Loading " + alarmTones.length + " Ringtones."); alarmsCursor.close(); setMathAlarm(alarm); }
Example 6
Source File: BroadcastReceiverActivity.java From AndroidDemo with MIT License | 5 votes |
@Override protected void setContentView() { setContentView(R.layout.activity_broadcast); testReceiver = new TestReceiver(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction("LocalBroadcast"); intentFilter.addAction("Broadcast"); // intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); LocalBroadcastManager.getInstance(this).registerReceiver(testReceiver, intentFilter); testReceiver2 = new TestReceiver(); registerReceiver(testReceiver2, intentFilter); RingtoneManager rm = new RingtoneManager(this); rm.setType(RingtoneManager.TYPE_NOTIFICATION); Cursor cursor = rm.getCursor(); if (cursor.moveToFirst()) { uri = cursor.getString(RingtoneManager.URI_COLUMN_INDEX) + "/" + cursor.getString(RingtoneManager.ID_COLUMN_INDEX); } if (TextUtils.isEmpty(uri)) uri = "content://media/internal/audio/media/0"; mp = new MediaPlayer(); // mp.reset(); // try { // mp.setDataSource(this, Uri.parse(uri)); // mp.setAudioStreamType(AudioManager.STREAM_NOTIFICATION); // mp.setLooping(true); //// mp.prepare(); // } catch (IOException e) { // e.printStackTrace(); // } }
Example 7
Source File: OSUtilities.java From Yahala-Messenger with MIT License | 5 votes |
public static Uri getMediaUri(String ringtoneTitle) { Uri parcialUri = Uri.parse("content://media/external/audio/media"); // also can be "content://media/internal/audio/media", depends on your needs Uri finalSuccessfulUri; RingtoneManager rm = new RingtoneManager(ApplicationLoader.applicationContext); rm.setType(RingtoneManager.TYPE_ALL); Cursor cursor = rm.getCursor(); cursor = ApplicationLoader.applicationContext.getContentResolver().query( MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Audio.Media.TITLE); cursor.moveToFirst(); while (!cursor.isAfterLast()) { // FileLog.e("finalSuccessfulUri",cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.TITLE))); if (ringtoneTitle.equalsIgnoreCase(cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.TITLE)))) { int ringtoneID = cursor.getInt(cursor.getColumnIndex(MediaStore.MediaColumns._ID)); finalSuccessfulUri = Uri.withAppendedPath(parcialUri, "" + ringtoneID); // FileLog.e("finalSuccessfulUri",finalSuccessfulUri.getPath()); return finalSuccessfulUri; } cursor.moveToNext(); } return null; }
Example 8
Source File: RingtonePickerDialog.java From ClockPlus with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { mRingtoneUri = savedInstanceState.getParcelable(KEY_RINGTONE_URI); } mRingtoneManager = new RingtoneManager(getActivity()); mRingtoneManager.setType(RingtoneManager.TYPE_ALARM); }
Example 9
Source File: AlarmUtils.java From PrayTime-Android with Apache License 2.0 | 5 votes |
public static Uri getRandomRingtone(Context context) { Uri alert = null; RingtoneManager ringtoneManager = new RingtoneManager(context); ringtoneManager.setType(RingtoneManager.TYPE_ALARM); int count = ringtoneManager.getCursor().getCount(); int attempts = 0; do { int random = (int) Math.random() * (count + 1); alert = ringtoneManager.getRingtoneUri(random); } while (alert == null && ++attempts < 5); return alert; }
Example 10
Source File: AlarmUtils.java From PrayTime-Android with Apache License 2.0 | 5 votes |
public static Map<String, Uri> getRingtones(Activity activity) { RingtoneManager manager = new RingtoneManager(activity); manager.setType(RingtoneManager.TYPE_RINGTONE); Cursor cursor = manager.getCursor(); Map<String, Uri> list = new LinkedHashMap<>(); while (cursor.moveToNext()) { String notificationTitle = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX); Uri notificationUri = manager.getRingtoneUri(cursor.getPosition()); list.put(notificationTitle, notificationUri); } return list; }
Example 11
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 12
Source File: ThemableRingtonePreference.java From boilr with GNU General Public License v3.0 | 5 votes |
public void setRingtoneType(String alertType) { mRingtoneType = getAlertInt(alertType); RingtoneManager ringtoneManager = new RingtoneManager(getContext()); mCurrentShowDefault = mShowDefault && alertType.equals(AlarmPreferencesFragment.DEFAULT) ? true : false; ringtoneManager.setType(mRingtoneType); final Cursor ringtones = ringtoneManager.getCursor(); List<String> entries = new ArrayList<String>(); List<String> entryValues = new ArrayList<String>(); if(mCurrentShowDefault) { mAppRingtone = mSharedPrefs.getString( SettingsFragment.PREF_KEY_DEFAULT_ALERT_SOUND, Conversions.getSystemRingtone(mRingtoneType, getContext())); entries.add(getContext().getString(R.string.default_value, Conversions.ringtoneUriToName(mAppRingtone, getContext()))); entryValues.add(AlarmPreferencesFragment.DEFAULT); } // Silent entries.add(getContext().getString(R.string.silent)); entryValues.add(""); String value; int id; Matcher m; for(ringtones.moveToFirst(); !ringtones.isAfterLast(); ringtones.moveToNext()) { entries.add(ringtones.getString(RingtoneManager.TITLE_COLUMN_INDEX)); value = ringtones.getString(RingtoneManager.URI_COLUMN_INDEX); m = p.matcher(value); if(!m.matches()) { id = ringtones.getInt(ringtones.getColumnIndex(MediaStore.MediaColumns._ID)); value += "/" + id; } entryValues.add(value); } setEntryValues(entryValues.toArray(new CharSequence[entryValues.size()])); setEntries(entries.toArray(new CharSequence[entries.size()])); }
Example 13
Source File: RingtonePickerActivity.java From ticdesign with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mHandler = new Handler(); Intent intent = getIntent(); /* * Get whether to show the 'Default' item, and the URI to play when the * default is clicked */ mHasDefaultItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); mUriForDefaultItem = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI); if (mUriForDefaultItem == null) { mUriForDefaultItem = Settings.System.DEFAULT_RINGTONE_URI; } if (savedInstanceState != null) { mClickedPos = savedInstanceState.getInt(SAVE_CLICKED_POS, POS_UNKNOWN); } // Get whether to show the 'Silent' item mHasSilentItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true); // Give the Activity so it can do managed queries mRingtoneManager = new RingtoneManager(this); // Get the types of ringtones to show mType = intent.getIntExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, -1); if (mType != -1) { mRingtoneManager.setType(mType); } mCursor = mRingtoneManager.getCursor(); // The volume keys will control the stream that we are choosing a ringtone for setVolumeControlStream(mRingtoneManager.inferStreamType()); // Get the URI whose list item should have a checkmark mExistingUri = intent .getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI); final AlertParams p = mAlertParams; p.mCursor = mCursor; p.mOnClickListener = mRingtoneClickListener; p.mLabelColumn = MediaStore.Audio.Media.TITLE; p.mIsSingleChoice = true; p.mOnItemSelectedListener = this; if (SHOW_BUTTONS) { p.mPositiveButtonIcon = getDrawable(R.drawable.tic_ic_btn_ok); p.mPositiveButtonListener = this; p.mNegativeButtonIcon = getDrawable(R.drawable.tic_ic_btn_cancel); p.mNegativeButtonListener = this; } p.mOnPrepareListViewListener = this; p.mTitle = intent.getCharSequenceExtra(RingtoneManager.EXTRA_RINGTONE_TITLE); if (p.mTitle == null) { p.mTitle = getString(R.string.ringtone_picker_title); } p.mAdapter = mWithHeaderCursorAdapter = new WithHeaderCursorAdapter(this, p.mCursor, p.mLabelColumn); setupAlert(); }
Example 14
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); }