Search code examples
androidaudiosmsringtone

Android - Setting Text Message Sound Does Not Change Sound?


My issue is that the code is not changing my Alarm tone, or the tone for when I get a text message.

The following works:

       private void setRingTone(int RawId, String HumanName, String fileName)
   {

       Uri path = Uri.parse("android.resource://"+ getPackageName() +"/raw/" + fileName);

       RingtoneManager.setActualDefaultRingtoneUri(
               getApplicationContext(), RingtoneManager.TYPE_RINGTONE,
               path);  
       Log .i("TESTT", "Ringtone Set to Resource: "+ path.toString());

       RingtoneManager.getRingtone(getApplicationContext(), path)
               .play();

   }

However these 2 do not:

  1. private void setTextTone(int RawId, String HumanName, String fileName) {

       Uri path = Uri.parse("android.resource://"+ getPackageName() +"/raw/" + fileName);
    
       RingtoneManager.setActualDefaultRingtoneUri(
               getApplicationContext(), RingtoneManager.TYPE_NOTIFICATION,
               path);  
       Log .i("TESTT", "Ringtone Set to Resource: "+ path.toString());
    
       RingtoneManager.getRingtone(getApplicationContext(), path)
               .play();
    

    }

Does anyone know why the Notification does not change the sound of SMS messages, but Ringtone works. It is basically the same code??

EDIT I found something on Stack Overflow here (But I do Not understand it can someone clarify?) http://stackoverflow.com/questions/9545906/how-do-i-change-the-android-sms-tone-despite-of-current-sms-tone-setting

Thanks in Advance!


Solution

  • So the solution is to copy the sound from the raw folder into the sdcard and from there do the following:

      File k = new File(path, filename);
    
      ContentValues values = new ContentValues();
      values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
      values.put(MediaStore.MediaColumns.TITLE, "TwiAppclip");
      values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/*");
      values.put(MediaStore.Audio.Media.ARTIST, "cssounds ");
      values.put(MediaStore.Audio.Media.IS_RINGTONE, false);
      values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
      values.put(MediaStore.Audio.Media.IS_ALARM, false);
      values.put(MediaStore.Audio.Media.IS_MUSIC, false);
    
      Uri uri = MediaStore.Audio.Media.getContentUriForPath(k
           .getAbsolutePath());
       //do a delete here before inserting
      Uri newUri = getApplicationContext().getContentResolver().insert(uri, values);
    
      RingtoneManager.setActualDefaultRingtoneUri(getApplicationContext(),
          RingtoneManager.TYPE_RINGTONE, newUri);