This is code that I am using to set the ringtone programmatically in my android application
Uri uri=Uri.parse("android.resource://"+getPackageName()+"/raw/do_you_wanna_know_why_i_use_a_knife");
RingtoneManager manager=new RingtoneManager(NatureSounds_FinalBuildActivity.this);
manager.setActualDefaultRingtoneUri(getApplicationContext(), RingtoneManager.TYPE_RINGTONE,uri);
RingtoneManager.getRingtone(getApplicationContext(), uri).play();
The ringtone plays perfectly in the application when I play using getRingtone method. But it doesn't play when a call is received and in the Settings->Sound->Phone ringtone it shows as Unknown Ringtone.
I am using Galaxy s2 as the device to test and the sound files are located in the raw folder in res. They are of mp3 format. Os Version is ICS