tech_learner
tech_learner

Reputation: 725

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 particular class I can use for it?

Upvotes: 0

Views: 5652

Answers (3)

Mostafa Rostami
Mostafa Rostami

Reputation: 1946

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);

Upvotes: 0

Rejinderi
Rejinderi

Reputation: 11844

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!

Upvotes: 2

dmon
dmon

Reputation: 30168

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 :) .

Upvotes: 0

Related Questions