开发者

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.getDef开发者_运维问答aultUri(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?


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜