0

I'm developing ,for educational purposes, a Android APP.

This APP have a GCMService and works well, but I'm trying to start a simple sound or alarm when the APP receive a certain message from GCM Service.

How I can do this? I'm searching for information, but always see the people start a Service or Activity, and I think this is much easy.

Thanks ALL!

Hypnotize
  • 143
  • 2
  • 17

1 Answers1

1

You can write the code into onMessage() of GCMIntentService like

@Override
    protected void onMessage(Context context, Intent intent) {
        Log.i(TAG, "Received message");
        String message = getString(R.string.gcm_message);
        displayMessage(context, message);
        // notifies user
        generateNotification(context, message);
        //Write here for sound notification 
        //for example 
        Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        Ringtone ringer = RingtoneManager.getRingtone(getApplicationContext(), notification);
        ringer.play();
    }

start a simple sound or alarm when the APP receive a certain message from GCM Service

You can put condition in above method and play soound. like

if ("XYZ".equals(message)) {
//Then Play a sound
        Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        Ringtone ringer = RingtoneManager.getRingtone(getApplicationContext(), notification);
        ringer.play();

}
Pankaj Kumar
  • 81,967
  • 29
  • 167
  • 186
  • It's works so good, but I need play a sound ALARM around 30 secs, not the default ringtone (In my telephone now sounds Hangouts ringtone). How I can modify the sound? How I can play the sound around 30 secs? – Hypnotize Jun 19 '13 at 20:56
  • see http://stackoverflow.com/questions/8414495/android-notification-to-play-sound-only – Pankaj Kumar Jun 20 '13 at 05:40