Saving sounds as ringtones using the title of the sound instead of number location
<p>I have a soundboard app in android that users can longpress the buttons to save sounds as either ringtones, notifications, or alarms. Everything works fine and the sounds are saved to the sdcard and set as the default sound but the sound names are set as the number location where they are in the app. For example if I saved the first sound, which is titled "laughing" it will save to sdcard and show up in ringtone list as "1", not "laughing". I want the sounds to be saved with their title not their number. </p>

<p>What do I need to change in my code to fix this?? I am using an array to set the sound titles to the buttons, etc. Here is the code I have which saves the sounds:</p>

<pre><code>public boolean setAsTone(int ressound, String filename, String toneType) {

    Log.v("File Name", "" + filename);
    Log.v("Tone Type", "" + toneType);
    byte[] buffer = null;
    InputStream fIn = getBaseContext().getResources().openRawResource(ressound);
    int size = 0;

    try {
        size = fIn.available();
        buffer = new byte[size];
        fIn.read(buffer);
        fIn.close();
    } catch (IOException e) {
        return false;
    }
    switch (Integer.parseInt(filename)) {

    }
    if (toneType.contains(getString(R.string.ringtone))) {
        path = "/sdcard/media/audio/"
                + getString(R.string.ringtone).toLowerCase() + "/";
        Log.v("Path", "" + path);
    } else if (toneType.contains(getString(R.string.notification))) {
        path = "/sdcard/media/audio/"
                + getString(R.string.notification).toLowerCase() + "/";
        Log.v("Path", "" + path);
    } else if (toneType.contains(getString(R.string.alarm))) {
        path = "/sdcard/media/audio/"
                + getString(R.string.alarm).toLowerCase() + "/";
        Log.v("Path", "" + path);
    }

    boolean exists = (new File(path)).exists();
    if (!exists) {
        new File(path).mkdirs();
    }

    FileOutputStream save;
    try {
        save = new FileOutputStream(path + filename);
        save.write(buffer);
        save.flush();
        save.close();
    } catch (FileNotFoundException e) {
        return false;
    } catch (IOException e) {
        return false;
    }

    sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
            Uri.parse("file://" + path + filename)));

    File ringtoneFile = new File(path, filename);

    ContentValues values = new ContentValues();
    values.put(MediaStore.MediaColumns.DATA, ringtoneFile.getAbsolutePath());
    values.put(MediaStore.MediaColumns.TITLE, filename);
    values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/ogg");
    values.put(MediaStore.Audio.Media.ARTIST, "Laughing");
    Log.v("getAbsolute Path", "" + ringtoneFile.getAbsolutePath());
    if (toneType.contains(getString(R.string.ringtone))) {
        values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
        values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
        values.put(MediaStore.Audio.Media.IS_ALARM, false);
        type = RingtoneManager.TYPE_RINGTONE;
        Log.v("Ring Type", "" + type);
    } else if (toneType.contains(getString(R.string.notification))) {
        values.put(MediaStore.Audio.Media.IS_RINGTONE, false);
        values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
        values.put(MediaStore.Audio.Media.IS_ALARM, false);
        type = RingtoneManager.TYPE_NOTIFICATION;
        Log.v("Ring Type", "" + type);
    } else if (toneType.contains(getString(R.string.alarm))) {
        values.put(MediaStore.Audio.Media.IS_RINGTONE, false);
        values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
        values.put(MediaStore.Audio.Media.IS_ALARM, true);
        type = RingtoneManager.TYPE_ALARM;
        Log.v("Ring Type", "" + type);
    }

    values.put(MediaStore.Audio.Media.IS_MUSIC, true);

    // Insert it into the database
    Uri ringtoneUri = null;
    Uri uri = MediaStore.Audio.Media.getContentUriForPath(ringtoneFile
            .getAbsolutePath());
    Log.v("Uri Path",""+uri);
    getContentResolver().delete(
            uri,
            MediaStore.MediaColumns.DATA + "=\""
                    + ringtoneFile.getAbsolutePath() + "\"", null);

    ringtoneUri = this.getContentResolver().insert(uri, values);
    Log.v("Ringtone Uri", "" + ringtoneUri);
    Log.v("Final Ring Type", "" + type);
    RingtoneManager.setActualDefaultRingtoneUri(getApplicationContext(),
            type, ringtoneUri);
    RingtoneManager.getActualDefaultRingtoneUri(getApplicationContext(), type);
    return true;
}
</code></pre>

<p>}</p>
