title: Set a sound file as ringtone and notification programmatically in Android
body: <p>I have two buttons in my app. One for setting a sound file as ringtone and another as notification. I am able to set the sound file as a ringtone but when I try to set it as notification, it removes the ringtone I previously added. Sound file is displayed only as notification. I want to set a sound file as both ringtone and notification via separate buttons.</p>
  
  <p>Code for ringtone:</p>
  
  <pre><code>File k = new File(baseDir,fileName);
  ContentValues values = new ContentValues();
  
  values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
  values.put(MediaStore.MediaColumns.TITLE, "Voicetransform ");  
  
  values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/wav");
  values.put(MediaStore.MediaColumns.SIZE, k.length());
  values.put(MediaStore.Audio.Media.ARTIST, R.string.app_name);
  values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
  values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
  values.put(MediaStore.Audio.Media.IS_ALARM, true);
  values.put(MediaStore.Audio.Media.IS_MUSIC, false);
  
  Uri uri = MediaStore.Audio.Media.getContentUriForPath(k
          .getAbsolutePath());
  context.getContentResolver().delete(
  uri,
  MediaStore.MediaColumns.DATA + "=\""
          + k.getAbsolutePath() + "\"", null);
  Uri newUri = context.getContentResolver().insert(uri, values);
  
  try {
      RingtoneManager.setActualDefaultRingtoneUri(
              context, RingtoneManager.TYPE_RINGTONE,
              newUri);
  } catch (Throwable t) {
  
  }
  </code></pre>
  
  <p>Code for notification:</p>
  
  <pre><code>ContentValues values = new ContentValues();
  values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
  values.put(MediaStore.MediaColumns.TITLE, "Voicetransform1");
  values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/wav");
  values.put(MediaStore.MediaColumns.SIZE, k.length());
  values.put(MediaStore.Audio.Media.ARTIST, R.string.app_name);
  values.put(MediaStore.Audio.Media.IS_RINGTONE, false);
  values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
  values.put(MediaStore.Audio.Media.IS_ALARM, true);
  values.put(MediaStore.Audio.Media.IS_MUSIC, false);
  
  Uri uri = MediaStore.Audio.Media.getContentUriForPath(k
      .getAbsolutePath());
  context.getContentResolver().delete(
      uri,
      MediaStore.MediaColumns.DATA + "=\""
          + k.getAbsolutePath() + "\"", null);
  Uri newUri = context.getContentResolver().insert(uri, values);
  
  try {
      RingtoneManager.setActualDefaultRingtoneUri(
          context, RingtoneManager.TYPE_NOTIFICATION,newUri);
  } catch (Throwable t) {
  
  }
  
  File k = new File(baseDir,fileName);
  </code></pre>