Hi people! I am stuck on this. I try some ways to set defautl ringtone but none works for me :S any idea, I have this:
int tipo -> I send RingtoneManager.TYPE_ALARM (TYPE_RINGTONE OR ALARM)
String tipostring -> I send the name of folder (“ringtones”, “notifications”, “alarms”);
setSonido(RingtoneManager.TYPE_RINGTONE, "ringtones");
public void setSonido(int tipo, String tipostring){
File newSoundFile = new File("/sdcard/media/", tipostring+".mp3");
Uri mUri = Uri.parse("android.resource://com.genaut.newapptest/raw/"+sonidoActual);
ContentResolver mCr = contexto.getContentResolver();
AssetFileDescriptor soundFile;
try {
soundFile= mCr.openAssetFileDescriptor(mUri, "r");
} catch (FileNotFoundException e) {
soundFile=null;
}
try {
byte[] readData = new byte[1024];
FileInputStream fis = soundFile.createInputStream();
FileOutputStream fos = new FileOutputStream(newSoundFile);
int i = fis.read(readData);
while (i != -1) {
fos.write(readData, 0, i);
i = fis.read(readData);
}
fos.close();
} catch (IOException io) {
}
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, newSoundFile.getAbsolutePath());
values.put(MediaStore.MediaColumns.TITLE, nombreActual);//Cambiar
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mpeg3");
values.put(MediaStore.MediaColumns.SIZE, newSoundFile.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, true);
values.put(MediaStore.Audio.Media.IS_ALARM, true);
values.put(MediaStore.Audio.Media.IS_MUSIC, false);
//
Uri uri = MediaStore.Audio.Media.getContentUriForPath(newSoundFile.getAbsolutePath());
Uri newUri = mCr.insert(uri, values);
try {
RingtoneManager.setActualDefaultRingtoneUri(getApplicationContext(), tipo, newUri);
} catch (Throwable t) {
Log.d("ringtone", "catch exception");
}
}
This code adds the record to new sound on (Settings-> Audio profiles -> Ringtone calls ) But not set how default, and if i set it, not play the sound :S
Thanks a lot! and sorry my english