Когда я запускаю сервис, я показываю уведомление. В Android ниже 9 это хорошо. Но в Android 9, когда я нажимаю кнопку «Домой», уведомление будет отменено, как только приложение закроется. это мой код
@Override
public int onStartCommand(Intent intent, int flags, int startId) {//____________________________ Start onStartCommand
SaveLog("onStart Service : " + getStringCurrentDate());
if (alarmNotify == null) {
Integer id = getApplicationContext().getResources().getInteger(R.integer.NotificationRun);
NotificationManagerClass managerClass =
new NotificationManagerClass(
getApplicationContext(),
getApplicationContext().getResources().getString(R.string.ServiceRun)
, true
, 3
);
alarmNotify = managerClass.getNotification();
startForeground(id, alarmNotify);
}
Calendar now = Calendar.getInstance();
Intent intent1 = new Intent(getApplicationContext(), ReceiverJobInBackground.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent1, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(getApplicationContext().ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, now.getTimeInMillis(), 60 * 1000, pendingIntent);
return Service.START_STICKY;
}//_____________________________________________________________________________________________ End onStartCommand
alarmNotify android .app.Notification
я установил разрешение:
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
это мой канал:
NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ONE_ID,
CHANNEL_ONE_NAME, notifManager.IMPORTANCE_HIGH);
notificationChannel.enableLights(true);
notificationChannel.setLightColor(context.getResources().getColor(R.color.colorPrimary));
notificationChannel.setShowBadge(true);
notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
getManager().createNotificationChannel(notificationChannel);
помогите пожалуйста .. танки