How is it possible to send a notification programmatically, when the App got completely closed?
Example: The User closed the App, also in the Android Taskmanager, a
You can use alarm manager to do this. Follow below steps :
1) Use alarmmanager to create an alarm of after X seconds.
Intent intent = new Intent(this, AlarmReceiver.class);
intent.putExtra("NotificationText", "some text");
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, ledgerId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, 'X seconds in milliseconds', pendingIntent);
2) Use a AlarmBroadCast receiver in your app.
Declare in manifest file :
3) In the broadcast receiver's on receive, you can create the notification.
public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// create notification here
}
}