Getting a list of available Ringtones in Android

后端 未结 2 669

I\'ve seen plenty of examples of how to set a default ringtone, but what I\'m more interested in is being able populate a drop down box list filled with the available ringtones

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-13 10:25

    This will return you the title and uri of all the ringtones available. Do with them what you wish!

    public Map getNotifications() {
        RingtoneManager manager = new RingtoneManager(this);
        manager.setType(RingtoneManager.TYPE_RINGTONE);
        Cursor cursor = manager.getCursor();
    
        Map list = new HashMap<>();
        while (cursor.moveToNext()) {
            String notificationTitle = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX);
            String notificationUri = cursor.getString(RingtoneManager.URI_COLUMN_INDEX) + "/" + cursor.getString(RingtoneManager.ID_COLUMN_INDEX);
    
            list.put(notificationTitle, notificationUri);
        }
    
        return list;
    }
    

提交回复
热议问题