views:

845

answers:

1

Hi there! I am fiddling around with a dialog that pops up and displays an alarm information. (I know, it has been documented that in Android it's "better" style to use notifications instead, but just like the alarm clock I want it to display a dialog on top of whatever you do to really get the users immediate attention - as the user expects this behavior I don't think it's bad style!)

Now - the only easy way I found is using the RingtoneManager.getRingtone() function to get a Ringtone object for the type "alarm".

Well, I can play that sound now using Ringtone.play() - but it plays the sound only once and I cannot figure out how to let it play endlessly until the user reacts, e.g. by touching the dialog anywhere or dismissing it using Cancel button provided.

Does anyone know how this can be accomplished easily? Thanks!

+1  A: 

Take a look at AlarmClock from Android's git repository. It might be helpful to check out the source code on how to play sounds for an expected duration.

Anthony Forloney
Thanks - that's a good starting point. But now I'm stuck with this source, I tried to get it to work here by downloading the cupcake snapshot. But I got so many compile errors! Some elements are not found or e.g. `new Virbrator()` states that the constructor is not public, etc. How on earth can I simply get this git-checkout to compile correctly here on my system? Do you know how?Thanks!
Zordid
The snapshot just contains the .java files referenced to `com.google.alarmclock`, the package header could be causing compilation errors.
Anthony Forloney
Hmm, so what do I have to do? All the errors seem extremely strange to me. For example there's a field `mContext` missing in the class `DigitalClock` - definitely a bug! But that source is seen by so many people: how can that happen to end up like that? Other errors are really that static finals do not exist like `Intent.ACTION_ALARM_CHANGED` - I cannot find this anywhere in the Android docs.But okay. I am going to look for the sound snippet now... would have been easier without all these compile errors....
Zordid
I wouldnt use the class *as is* per se, just a guide to see how they play an alarm for a duration to give you an idea on what to do.
Anthony Forloney
You're right. It's really the only thing to do with it. And: I found the place where they play the sound - rather complicated as many things I so far did not think of have to be kept in mind. For example: detecting whether you're in a call, testing for a sound that might be on the SD card is available and so on! I hoped it would be easier - as easy as it is to put a notification with an alarm sound! But it isn't! :-( Thanks for that hint!
Zordid
No problem, best of luck.
Anthony Forloney