Search code examples
androidringtonevibration

Android Play default ring-tone and vibration alert on receiving text Messages


HI,
I am working on a small android application. Application receive text messages from other phones. I want to Play default ring-tone and vibration alert onReceiving Messages event according to user current settings. i.e. If mobile phone isn't silent and vibration is off, then it plays ring-tone and if mobile phone is silent and vibration is on, it should vibrate onRecieve event.
Thank you


Solution

  • junto,

    One you set your notification, you just have to add flags to indicate you want the default sound to play as well as vibrate.

    Notification notification = new Notification(android.R.drawable.ic_popup_reminder,
                "My Notification", System.currentTimeMillis());
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;