How schedule local notifications Android?
android, datetime, localnotification, notifications
Solution
To schedule local notification you need to know some of the things which are used to schedule the notification like:
`BroadcastReceiver`s
`IntentFilter`s
`AlarmManager`
`NotificationService`
`PendingIntent`
In the `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);
}
The above code will schedule an alarm after 15 seconds. After 15 seconds it will broadcast the `NotificationIntent`.
The action specified in the Intent constructor is defined in the AndroidManifest.xml
To understand the full working of local notification and to see a sample notification code check out this article
Problem
I have a question about local notifications in Android. I am developing an application where in the first part I must receive all meetings of the 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 to schedule local notifications at a given date?