在 Android 中设置铃声
我的 res/raw 文件夹中有声音文件,我想通过单击按钮选择一个声音设置为铃声。想知道我该怎么做?
Possible Duplicate:
How to set ringtone in Android from my activity?
I have sounds files in my res/raw folder and i want to select a sound to set as a ringtone on the click of a button. Wonder how can i do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
@Maxood
@Clive 的代码是您设置铃声所需的代码。您将需要文件的绝对路径,而您无法从原始资源中获得该路径。
解决方案是先获取资源文件 asset 并将其写入 SD 卡,然后再将其交给内容解析器进行插入。
然后您可以使用之前发布的解决方案
不要忘记在清单中写入权限
希望
这会有所帮助
@Maxood
The code from @Clive is what you need to set the ringtone. You will need the absolute path to the file, which you can't get from a raw resource.
The solution is to get the resource file asset and write it to the sdcard 1st, before you give it to the content resolver for insertion.
Then you can use the previously posted solution
Don't forget to write the the permission
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
in your manifest
hope this helps
试试这个,它对我有用:
Try this, it works for me:
希望现在您已经让您的程序按照您想要的方式运行。不过,仅供记录,您应该考虑将文件保存到 SD 卡的铃声文件夹下。确保它是小写的,因为这在 Android 中很重要。
Hopefully by now you have gotten your program working the way you wanted. Just for the record though, you should look into saving the file to the sdcard under a ringtones folder. Make sure it is lower cased as that does matter in Android.
我使用“Rings Extended” http://www.androidapps.com/t/rings-extended< /a>
安装该应用程序后,当您要更改铃声时,您可以选择选择铃声扩展。还可以使用“Ringdroid”编辑铃声。
I use "Rings Extended" http://www.androidapps.com/t/rings-extended
With that app installed when you go to change your ringtone you will have the option to select Rings Extended. Also use "Ringdroid" to edit ringtones.