0

I want to generate a notification sound after a certain event on Google Glass. This is what I have tried

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                                                .setSmallIcon(R.drawable.ic_action_done)
                                                .setContentTitle("Message Receied")
                                                .setContentText("New message received")
                                                .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));

    //alert
    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    manager.notify(1, builder.build());

As well as this

Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        Ringtone r = RingtoneManager.getRingtone(context, notification);
        r.play();

The first code snippet doesn't return anything nor does it do anything. I'm unsure on how Glass handles notifications considering the lack of a notification center. The second code snippet throws the following error in logcat

06-02 15:05:30.248: D/MediaPlayer(32271): Couldn't open file on client side, trying server side
06-02 15:05:30.279: E/MediaPlayer(32271): Unable to create media player
06-02 15:05:30.279: D/Ringtone(32271): Problem opening; delegating to remote player

Does anyone have an idea on how to generate a sound?

Thank you

matiash
  • 54,791
  • 16
  • 125
  • 154
Clocker
  • 1,316
  • 2
  • 19
  • 29

2 Answers2

2

Not sure if that solve your issue, but you can generate a sound in glass with AudioManager like:

mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

then,

mAudioManager.playSoundEffect(Sounds.TAP);

or

mAudioManager.playSoundEffect(Sounds.SUCCESS);

It's not a notification sound, but maybe you just need to generate a sound?, I'm not sure where your event happens...

fpanizza
  • 1,589
  • 1
  • 8
  • 15
0

It seems like I end up answering my own question but here is the answer if above doesn't work:

private SoundPool mSoundPool;
private int mAlertReceived;
mSoundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
         mAlertReceived = mSoundPool.load(context, R.raw.tinkerbell, 1);

protected void playSound(int soundId) {
        mSoundPool.play(soundId,
                        1 /* leftVolume */,
                        1 /* rightVolume */,
                        1,
                        0 /* loop */,
                        1 /* rate */);  
    }

I got this code from the GDK Stopwatch samples. There is an .ogg file in the res/raw/

Clocker
  • 1,316
  • 2
  • 19
  • 29