특정 시간에 사용자에게 표시되는 일부 인앱 알림이 있지만 응용 프로그램을 닫을 때 아무 것도 표시되지 않습니다.응용 프로그램이 닫힐 때 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);
방송 수신기 : 그것은 scTime에 관해서
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);
}
}
}
그래서, 앱이 종료되는 경우에도, 나는 알림을 트리거하고 싶습니다.
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>
을하지만 아무것도가 표시되지 않습니다 내가 잘못 뭐하는 거지 ... 다음과 같이 그래서 나는 PendingIntent하여 서비스를 호출하는거야?
당신은'BroadcastReceiver'에서 전화 서비스를하고 있습니까? – Marat
전체 코드로 내 게시물을 편집했습니다. BroadCastreceiver를 게시하고 AlarmManager의 설정을 완료했습니다. 나는 BOOT_COMPLETED 같은 것을 매니 페스트에서해야합니까? –
매니페스트 파일도 필요합니다. 매니페스트에'broadcastReceiver'와'service'를 등록하셨습니까? – Marat