All right, I seem to have accidentally figured this out. Hopefully my explanation can help others having similar problems.
The problem seems to be not with the .nomedia file or with the parameters in the ContentValues (my first guesses), but rather with the names of the directories. Apparently, when you save ringtones or notifications to the SD card, you HAVE to put them in a directory called "ringtones" or "notifications." It doesn't seem to matter what the parent directory is called (e.g. "/sdcard/foo/ringtones"), but the names of the bottom-level directories have some special significance. For instance, if you save an audio file to /sdcard/ringtones, and insert it into the MediaStore with IS_NOTIFICATION and IS_RINGTONE both set to true, the file will be visible as both a ringtone and a notification - at least until you reboot. Once you reboot, Android will overwrite those values and set everything to false except for IS_RINGTONE, so it will no longer show up as a notification. Likewise for /sdcard/notifications, except that it will set everything to false except IS_NOTIFICATION. So this means you apparently can't have an audio file that is both a ringtone and a notification - if you want it to survive a reboot, anyway. And if you save the file to some other directory name (e.g. /sdcard/ foo), then on reboot Android will just delete the row from the "audio_meta" table entirely, and the files will not show up as either a ringtone or a notification (which is what was happening to me). Or, if you don't have a .nomedia file in that folder, it might try to reinterpret it as a IS_MUSIC audio file, meaning it will show up in the Music app. Also, Android will rename the title of the ringtone to be whatever the filename is minus the filetype suffix. So I have to save the file as the MediaStore.MediaColumns.TITLE value plus ".ogg", or else Android will just rename it for me after a reboot. I'm glad that I found a solution, but this feels really hacky. Is there a better way to do this? Also, does anyone know where the documentation is for "ringtones" and "notifications" being keywords for folder names? I looked in both RingtoneManager and MediaStore, but couldn't find any mention of it. Also, I've only tested this on a Nexus One running Eclair, so I'm not sure if other phones or Android versions show the same behavior. On May 23, 3:35 pm, Nolan Lawson <nolan.law...@gmail.com> wrote: > I'm having a problem creating ringtones from files saved to the SD > card. I have succeeded in getting the information to be written to > the MediaStore database, and the files do show up in Settings -> Sound > & Display -> Phone ringtone. However, as soon as I reboot the phone, > the files disappear from the list of ringtones. > > The only clue I have is that the database in /data/data/ > com.android.providers.media/databases/external-<guid>.db is getting > its rows deleted on startup. The files themselves are not changing. > Even stranger is that, if I simply copy the file from the SD card to > the files/ directory of the internal storage directory for my app, and > then save THAT file as the ringtone, it works! However, it doesn't > really seem feasible to me to force the user to keep two copies of the > audio file. > > I do have a .nomedia file in the audio files directory (to avoid the > files showing up in the Music app), but I have tested this with and > without the .nomedia file and the same problem occurs. > > Below is my code for creating the ringtone/notification. Any > suggestions for fixing this bug? The users of my app would be really > grateful if I figured this out. Thanks!! > > MediaPlayer mediaPlayer = new MediaPlayer(); > mediaPlayer.setDataSource(filename); > mediaPlayer.prepare(); > int duration = mediaPlayer.getDuration(); > > File file = new File(filename); > > ContentValues values = new ContentValues(); > values.put(MediaStore.MediaColumns.DATA, filename); > values.put(MediaStore.MediaColumns.TITLE, > ringtoneNameTextView.getText().toString()); > values.put(MediaStore.MediaColumns.SIZE, file.length()); > values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/ogg"); > values.put(MediaStore.Audio.Media.ARTIST, "Artist Name"); > values.put(MediaStore.Audio.Media.DURATION, duration); > values.put(MediaStore.Audio.Media.IS_RINGTONE, true); > values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true); > values.put(MediaStore.Audio.Media.IS_ALARM, false); > values.put(MediaStore.Audio.Media.IS_MUSIC, false); > > newUri = getContentResolver().insert(uri, values); > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group > athttp://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en