Pergunta

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?

Foi útil?

Solução

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.

Outras dicas

  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.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top