AlarmManager не срабатывает при закрытии приложения
У меня есть некоторые уведомления в приложении, чтобы показать пользователям в определенное время, но ничего не отображается, когда приложение закрыто.
Установка будильника:
Intent alarmIntent = new Intent(mMotherActivity, ReminderAlarmManager.class);
if (ReminderNotificationType.CHANGE_LENS.equals(notificationType)) {
alarmIntent.putExtra("NOTIFICATION_TYPE", "REMINDER");
} else {
alarmIntent.putExtra("NOTIFICATION_TYPE", "ORDER");
}
long scTime = alarmDate.getTime();
PendingIntent pendingIntent = PendingIntent.getBroadcast(mMotherActivity, 0, alarmIntent, 0);
AlarmManager alarmManager = (AlarmManager) mMotherActivity.getSystemService(mMotherActivity.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, scTime, pendingIntent);
приемник вещания:
public class ReminderAlarmManager extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String notificationType = intent.getStringExtra("NOTIFICATION_TYPE");
if(notificationType.equalsIgnoreCase("ORDER"))
{
Intent i = new Intent(context, OrderReminderNotificationService.class);
context.startService(i);
}
else if(notificationType.equalsIgnoreCase("REMINDER"))
{
Intent i = new Intent(context, ReminderNotificationService.class);
context.startService(i);
}
}
}
Поэтому, когда дело доходит до scTime, даже если приложение закрыто, я хотел бы вызвать уведомление. Итак, я вызываю сервис PendingIntent следующим образом:
public class OrderReminderNotificationService extends IntentService {
public OrderReminderNotificationService(String name) {
super(name);
}
@Override
protected void onHandleIntent(Intent intent) {
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
Context context = getApplicationContext();
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
context);
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
mBuilder.setContentTitle("Notification");
mBuilder.setContentText(context.getString(R.string.renewOrderNotificationMsg));
mBuilder.setSmallIcon(R.mipmap.ic_launcher);
mBuilder.setSound(uri);
mBuilder.setAutoCancel(true);
Intent notificationIntent = new Intent(this, LoginActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(2, mBuilder.build());
}
Часть в манифесте, касающаяся этого:
<receiver android:name="com.company.utils.ReminderAlarmManager">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Но ничего не появляется ... Что я делаю не так?