如何安排本地通知的Android? [英] How schedule local notifications Android?
问题描述
我有一个关于Android的本地通知的问题。我正在开发,其中第一部分必须得到公司的所有会议,我自己的服务器(这个我已经实现)的应用程序,而第二部分我必须在每次会议前通知一天,但与当地的通知。
i have a question about local notifications in Android. I am developing an application where in first part must receive all meetings of company of my own server (This i have achieved), and the second part i must notify one day before each meeting, but with local notifications.
如何安排,在指定日期本地通知?
How schedule local notifications at given date?
推荐答案
要安排本地通知你需要知道一些这是用来调度像
To schedule local notification you need to know some of the things which are used to schedule the notification like
BroadcastReceivers IntentFilters AlarmManager NotificationService PendingIntent
BroadcastReceivers IntentFilters AlarmManager NotificationService PendingIntent
在MainActivity做以下
In MainActivity do the following
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
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.SECOND, 15);
alarmManager.setExact(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), broadcast);
}
以上code将在15秒后设定闹钟。 15秒后,它会播放notificationIntent。
The above code will schedule an alarm after 15 seconds. After 15 seconds it will broadcast the notificationIntent.
在Intent构造函数中指定的操作在AndroidManifest.xml中定义
The action specified in the Intent constructor is defined in the AndroidManifest.xml
要了解本地通知的全部工作和看样品通知code看看这篇文章 - 的 http://www.singhajit.com/schedule-local-notification-in-android/
To understand the full working of local notification and to see a sample notification code check out this article - http://www.singhajit.com/schedule-local-notification-in-android/
这篇关于如何安排本地通知的Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!