开发者

Alarm / Alert sound in Android

I am working on an Android project and I want to raise some kind of alert or sound. I have implemented a countdown timer and once the countdown timer stops, an alarm or alert sound should be raised.

Any idea how can I implement this in Android. Is there any particul开发者_如何转开发ar class I can use for it?


You could use the notification class.. look here http://developer.android.com/guide/topics/ui/notifiers/notifications.html

if you don't need notification and just wants to play lets say a mp3 file you could use the MediaPlayer class http://developer.android.com/reference/android/media/MediaPlayer.html

or if you prefer to play a raw audio file you can use the AudioManager together with the SoundPool class from android.media package. do look for examples on the internet heres a good example http://android-er.blogspot.com/2010/11/play-foreground-and-background-music.html

good luck with your codes!


The source code for Android's clock/alarm system is available here, maybe that will lead you in the right direction, granted, it might be overkill, but it's the first thing that came to my mind when the "alarm" word was mentioned :) .


create raw folder in your resource and copy your song then use this code

notification.sound = Uri.parse("android.resource://com.mosi.persianbirthday/" + R.raw.tavalod);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜