Reputation: 1904
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
Reputation: 1006869
Does anybody know why this doesn't work?
Here are some possibilities:
Your device may not use an LED for notifications.
Your device may not have a vibration motor.
You may not have requested the VIBRATE
permission.
The default lights for this device is "none", even though the device is capable of using an LED for notification.
The default vibration pattern for this device is "none", even though it has a vibration motor.
Something's messed up in the way you are constructing your flags
-- switching to Notification.Builder
or NotificationCompat.Builder
might help.
Upvotes: 1