Set a combination of Vibration, Lights or Sound for a notification in android

Viewed 15857

I wan to provide the user with the option of choosing Lights, Sounds or Vibration or a combination of these three for alerts on Notification.

In android docs I saw that there is an option of DEFAULT_ALL where in all the three methods of alerts will be used.

Else there is an option choosing any one of them (DEFAULT_LIGHTS, DEFAULT_VIBRATE, DEFAULT_SOUND).

Is there any way by which a combination of for example SOUND and VIBRATION but no LIGHTS and other combinations can be made?


EDIT

Notification.Builder's (from prolink007's answer) method setDefaults(int default) says that:

The value should be one or more of the following fields combined with bitwise-or: DEFAULT_SOUND, DEFAULT_VIBRATE, DEFAULT_LIGHTS.

How should this be used?

5 Answers

For portability I prefer NotificationCompat.
User will possibly prefer his/her default values. In NotificationCombat you can set vibration, light and sound to user's default settings like this:

.setDefaults(-1)

where "-1" matches to DEFAULT_ALL: http://developer.android.com/reference/android/app/Notification.html#DEFAULT_ALL

Not that you must request for VIBRATE permission, else you will get an error. Add this to your Android manifest file:

<uses-permission android:name="android.permission.VIBRATE" />
Related