Search code examples
androidaudionotificationsandroid-c2dm

how can i play a sound when device receive an C2DM message


i have read for hours about how to start play a sound the way i want
but i cannot find an answer.

Here goes,
When device receive a C2DM push im displaying a Notification.
User can click the Notficationand my activity start.

Everything works grate.

Now I would like to create a phone-call-type of ring-sound
so it sounds like there's an incoming Voice call.

User pick up phone and notice my Notification presses it
and the sound stop playing.

Or even better, the C2DM message trigger my activity to start with a phone-call-type of ring-sound.

When user touch the phone the sound stop playing

any help in any direction would be grate


Solution

  • Set the sound data member of your Notification to a Uri pointing to the ringtone you want to have played when the Notification is displayed. Ideally, you let the user pick their own ringtone (e.g., via a RingtonePreference) rather than forcing a certain ringtone on them.

    Or even better, the C2DM message trigger my activity to start with a phone-call-type of ring-sound.

    Popping up an activity like this, when the user might be in the middle of something else, is infrequently a good idea.