0
A
回答
1
您可以使用DatePicker从用户获取Date。 使用报警管理器设置设置报警,然后onReceive方法建立通知。
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent notificationIntent = new Intent("android.media.action.DISPLAY_NOTIFICATION");
notificationIntent.addCategory("android.intent.category.DEFAULT");
PendingIntent broadcast = PendingIntent.getBroadcast(this, 100, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, d); // Date for your notification
cal.add(Calendar.MONTH, m); // Date for your notification
cal.add(Calendar.YEAR, y); // Date for your notification
alarmManager.setExact(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), broadcast);
创建一个新的Java文件AlarmReceiver.java 在下面的代码清单中添加
<receiver android:name=".AlarmReceiver">
<intent-filter>
<action android:name="android.media.action.DISPLAY_NOTIFICATION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
在你想要创建一个提醒应用@梅森理查德森AlarmReceiver.java
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
public class AlarmReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
Intent notificationIntent = new Intent(context, NotificationActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(NotificationActivity.class);
stackBuilder.addNextIntent(notificationIntent);
PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
Notification notification = builder.setContentTitle("Demo App Notification")
.setContentText("New Notification From Demo App..")
.setTicker("New Message Alert!")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentIntent(pendingIntent).build();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notification);
}
}
相关问题
- 1. 向日历添加提醒
- 2. 向日历添加提醒
- 3. 向服务器端添加提醒消息提交按钮
- 4. 如何在日历中添加提醒
- 5. UILocalNotification - 需要提醒/通知
- 6. 最新通知提醒
- 7. 根据提醒通知添加一个增量
- 8. 通过意向向Google日历添加时间和日期
- 9. Sharepoint日历中的日期提醒
- 10. Python中的周期性日期提醒
- 11. 向@Today添加日期
- 12. 如何使用PHP通过Google Calendar API添加大量事件通知提醒?
- 13. 如何在Google日历网址中添加提醒提醒时间
- 14. 向日期添加一个星期()
- 15. 生日提醒
- 16. Android:在状态栏通知上添加一个按钮
- 17. 苹果推送通知证书到期提醒
- 18. PHP MYSQL日期电子邮件提醒
- 19. 事件日期的FullCalendar提醒
- 20. 如何使用jquery提醒(日期)?
- 21. PHP中的消息通知提醒
- 22. iOS中的提醒/通知框架(5?)
- 23. 在C#中获取Tfs通知/提醒#
- 24. 提醒/事件没有被通知
- 25. DNS IP检查cpanel提醒/通知
- 26. Tabbar环境中的通知提醒
- 27. 如何给通知添加标志(状态栏通知)?
- 28. 通知栏关闭按钮
- 29. 是否可以为一个本地通知添加多个提醒?
- 30. 提醒只在添加新提醒时执行
做 – Lampard