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. 在特定日期在android中设置通知提醒
- 5. 向服务器端添加提醒消息提交按钮
- 6. 如何在日历中添加提醒
- 7. 我们如何添加提醒日历
- 8. 添加提醒日历的Android
- 9. 向后模/提醒周期
- 10. ios5通知提醒样式
- 11. 最新通知提醒
- 12. UILocalNotification - 需要提醒/通知
- 13. Android通知提醒用户
- 14. 根据提醒通知添加一个增量
- 15. 添加日期栏并生成新栏?
- 16. 通过意向向Google日历添加时间和日期
- 17. Sharepoint日历中的日期提醒
- 18. Python中的周期性日期提醒
- 19. 向@Today添加日期
- 20. 如何使用PHP通过Google Calendar API添加大量事件通知提醒?
- 21. 如何根据来自javascript的调用向通知栏添加通知?
- 22. 如何在Google日历网址中添加提醒提醒时间
- 23. 向日期添加一个星期()
- 24. 生日提醒
- 25. 添加鉴于上述通知栏
- 26. 谷歌日历API通知事件提醒
- 27. 苹果推送通知证书到期提醒
- 28. Android:在状态栏通知上添加一个按钮
- 29. 在MVC寻找提醒或通知4
- 30. 通知消息/提醒消息和UICollectionView:
做 – Lampard