Question

I am using following code for notification. It should vibrate and make sound at the time of event. But it is giving sound when the notification is creating, although the notification time is after 30 min.

final Notification notifyDetails = new Notification(R.drawable.icon, "Myapp",nextAlarmTime);
Context context = getApplicationContext();
CharSequence contentTitle = "Viramune";
CharSequence contentText = notificationAlart;

Intent notifyIntent = new Intent(context, Myapp.class);
PendingIntent intent1 = PendingIntent.getActivity(ViewDoughnut.this, 0, notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent1);


notifyDetails.flags = Notification.FLAG_ONLY_ALERT_ONCE;
notifyDetails.defaults |= Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE;

mNotificationManager.notify((int) editEventid, notifyDetails);

What is the problem in my code?

Was it helpful?

Solution

Android does exactly what it told to do:

mNotificationManager.notify((int) editEventid, notifyDetails);

This line creates a notification. You should use AlarmManager to schedule your notification in future.

OTHER TIPS

  1. The third parameter to the Notification constructor is not used to determine when to shoot the notification, but is just used for display and sort.
  2. I believe you're trying to do something that needs to be done using AlarmManager, and not Notification.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top