Zero
Zero

Reputation: 1904

Notification doesn't vibrate or show lights

For an App I am developing, I want to send the user a very attention-demanding notification. To do this, I have the following code:


public void showNotification() {
    // Show a notification in the notification bar
    Notification notification = new Notification(R.drawable.ic_launcher, "Notification", System.currentTimeMillis());
    notification.flags = Notification.PRIORITY_MAX | Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.FLAG_INSISTENT | Notification.DEFAULT_LIGHTS;

    Intent notificationIntent = new Intent(this, MainActivity.class);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    notification.setLatestEventInfo(this, "Title", "Text", contentIntent);

    mNotificationManager.notify(R.string.app_name, notification);
}

And in the manifest:

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

However, this doesn't vibrate or show lights. Does anybody know why this doesn't work?

Upvotes: 0

Views: 910

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006869

Does anybody know why this doesn't work?

Here are some possibilities:

  1. Your device may not use an LED for notifications.

  2. Your device may not have a vibration motor.

  3. You may not have requested the VIBRATE permission.

  4. The default lights for this device is "none", even though the device is capable of using an LED for notification.

  5. The default vibration pattern for this device is "none", even though it has a vibration motor.

  6. Something's messed up in the way you are constructing your flags -- switching to Notification.Builder or NotificationCompat.Builder might help.

Upvotes: 1

Related Questions