Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RingtoneManager returning null ringtone

I'm using RingtoneManager, and apparently on some phones it returns null all of the time. I know it returns null if the sound is silent or it cant find the tone. Why would null be returned if the sound is on and there is a tone? The code works on my nexus s....

Here is what I am using:

Ringtone ringtone;
ringtone = RingtoneManager.getRingtone(context, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
if(ringtone == null)
{
    Log.d("Debug", "ringtone is null");
}
else
{
    ringtone.play();
}

I have all permissions enabled to play ringtone (it works on my phone) and even have SD card permissions enabled just in case the ringtone is on the SD card. Any thoughts?

like image 230
atomicbaum Avatar asked Mar 23 '11 22:03

atomicbaum


2 Answers

I just fall into what the problem is. If the user have "Silent" like notification sound the function:

RingtoneManager.getRingtone(context, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))

returns null. And that explains why only some users find this issue.

like image 164
Brais Gabin Avatar answered Oct 15 '22 04:10

Brais Gabin


If you copy a costum sound onto your phone that is stored on the external storage, the RingtoneManager is not able to open it unless your app has the permission to access the external storage.

add missing permission to your manifest file:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

Took me some time to figure this out, while not getting the correct title of costum ringtones some user had on their devices

like image 36
kirmandi Avatar answered Oct 15 '22 04:10

kirmandi