我正在使用以下代码进行通知。它应该在事件发生时振动并发出声音。但是它在创建通知时发出声音,尽管通知时间是在 30 分钟之后。
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);
我的代码有什么问题?
最佳答案
Android 完全按照它的指示去做:
mNotificationManager.notify((int) editEventid, notifyDetails);
这一行创建一个通知。你应该使用 AlarmManager安排您将来的通知。
关于Android通知振动时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5337533/