0

In an application I am writing a use the Ringtone class to alert the user when some events occurs. So far everything is working but from the possibility to use other ringtones than the ones I have already installed in the system.

I placed a file named buzzer.mp3 in the assets folder and I unsuccessfully try to set it in the following way:

    Uri ringtoneUri = Uri.parse("file:///android_asset/buzzer.mp3")
    Ringtone ringtone = RingtoneManager.getRingtone(getApplicationContext(),
            ringtoneUri);

I used AssetsManager to check that the file is there and it actually founds it so I cannot really get the reason why I cannot set it. The operation logs the following error:

E/﹕ Failed to open file '/android_asset/buzzer.mp3'. (No such file or directory)
mariosangiorgio
  • 5,520
  • 4
  • 32
  • 46
  • who told you that you can use ("file:///android_asset/buzzer.mp3" ? – pskink Nov 03 '13 at 10:59
  • @pskink I did some research and I found that it should be the `Uri` for my resource. Is the problem in the `Uri` I provide or in permissions for the `RingtoneManager` that cannot access assets? – mariosangiorgio Nov 03 '13 at 11:02
  • 1
    the problem is the wrong uri, what you can do is to write your custom ContentProvider and use it as an uri – pskink Nov 03 '13 at 11:12
  • @pskink can you please provide me a link to an example I should follow? I am a little confused because I found in several Q&A, like [this one](http://stackoverflow.com/questions/4820816/how-to-get-uri-from-an-asset-file), the `Uri` syntax I used – mariosangiorgio Nov 03 '13 at 11:16
  • it works only for a WebView, so you have to write your custom ContentProvider – pskink Nov 03 '13 at 11:29
  • 1
    when creating custom ContentProvider you need to override only one method: openAssetFile() – pskink Nov 03 '13 at 12:13

0 Answers0