Я использую следующий код:Уведомление не появляется на переднем плане службы
private void startForeground(boolean isActive) {
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(getString(isActive ? R.string.title_agent_active : R.string.title_agent_inactive))
.setContentIntent(pendingIntent)
.build();
startForeground(1, notification);
}
и
@Override
protected void onHandleIntent(Intent intent) {
startForeground(true);
...
С этим уведомлением код не отображается.
Но если я заменил startForeground (...) с NotificationManager.notify (...) - он отображает уведомление, поэтому, я думаю, что хотя бы код здания уведомления одобрен.
Где может быть проблема?
Проблема в том, что она не появляется вообще :( – arts777
Как долго это действительно возвращает метод onHandleIntent()? – kleinsenberg
Смена IntentService для обслуживания работала для меня .. – Vinay