I am trying to add a custom ringtone for my android app. All i have done is created a raw folder in res directory and added a mp3 file there as a ringtone using below code. some how only default notification tone from Android app has been played on calling this ringtone. Any help would be highly appreciated.
private synchronized void startRinging() {
try {
Uri ringtoneUri = Uri.parse("android.resource://" + getPackageName() + "/raw/ringnow.mp3");
RingtoneManager.setActualDefaultRingtoneUri(
getApplicationContext(), RingtoneManager.TYPE_RINGTONE, ringtoneUri
);
r = RingtoneManager.getRingtone(getApplicationContext(), ringtoneUri);
if (r != null) {
r.play();
}
} catch (Exception e) {
e.printStackTrace();
}
}
private synchronized void stopRinging() {
r.stop();
}
maybe you shouldn`t write ".mp3" in your URI