Şimdiye kadar, hizmetimi başlatmak için kodumu ContextCompat.startForegroundService(context, intentService);
kullanmaya yönlendirdim. Bu şekilde, android < 26 ve android 26 (Oreo) üzerinde de çalışır.Oreo - Önplan hizmeti ön plan bildirimini göstermiyor
Hala bir fark görüyorum, android oreo özel ön plan bildirimimi göremiyorum (sadece "app arka planda çalışıyor" bildirimini görüyorum). Orada da bir şey ayarlamalı mıyım?
hizmetim şöyle görünür:
public class BaseOverlayService extends Service {
@Override
public void onCreate() {
super.onCreate();
moveToForeground();
}
private void moveToForeground() {
Notification notification = ...;
super.startForeground(NOTIFICATION_ID, notification);
}
}
Resmi örneği
Bu örnek (https://github.com/googlesamples/android-play-location/blob/master/LocationUpdatesForegroundService/app/src/main/java/com/google/android/gms/location/sample/locationupdatesforegroundservice/LocationUpdatesService.java#L200) Aşağıdaki kullanması gerektiğini, yorum olarak gösterir, ancak startServiceInForeground
yok ...
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O) {
NotificationManager mNotificationManager = ((NotificationManager) getSystemService(NOTIFICATION_SERVICE));
mNotificationManager.startServiceInForeground(new Intent(this, BaseOverlayService.class), NOTIFICATION_ID, notification);
} else {
startForeground(NOTIFICATION_ID, notification);
}
Edit
Benim bildirim şimdiye kadar API < 26 ile android cihazların binlerce üzerinde çalışıyor hangi bu gibi oluşturulur:
protected Notification foregroundNotification(int notificationId)
{
boolean paused = MainApp.getPrefs().sidebarServicePaused();
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setSmallIcon(R.drawable.icon_not);
builder.setContentIntent(notificationIntent());
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.icon));
builder.setContentTitle(getString(R.string.derived_app_name));
builder.setContentText(getString(checkStatus() ? (paused ? R.string.service_notification_text_paused : R.string.service_notification_text_running) : R.string.service_notification_text_preparing));
builder.setColor(Color.parseColor("#25baa2"));
if (MainApp.getPrefs().hideNotificationIcon())
builder.setPriority(NotificationCompat.PRIORITY_MIN);
else
builder.setPriority(NotificationCompat.PRIORITY_MAX);
if (paused)
builder.addAction(R.drawable.ic_play_arrow_black_24dp, getString(R.string.resume), resumeIntent(this));
else
builder.addAction(R.drawable.ic_pause_black_24dp, getString(R.string.pause), pauseIntent(this));
return builder.build();
}
gibi katma bağlantı zaten oldukça iyi util
Sonra, teşekkürler kullanabilirsiniz. Yine de bir soru: Bu değişiklik, android oreo'da artık bir ön plan servisi için bir bildirim göstermeye gerek olmadığı anlamına mı geliyor? İnsanlar bana benim app bildirimi olmadan android oreo üzerinde çalışıyor bana söylediler ... – prom85
eghmmm ... Aslında bildirim olmadan çalışamaz. Arka planda çalışmalara, Android'de etkinlik veya bildirim gibi görünür bileşenler olmadan izin verilmez. Hizmetinizi görünür bileşen sistemi olmadan çalıştırırsanız, bir süre sonra onu öldürür. Arka plan işi yapmak istiyorsanız servis için bildirim almanız gerekir. Belirli bir süre içinde arka planda bir şeyler çalıştırmanız gerekiyorsa, [firebase iş dağıtıcısı] 'nı kontrol etmeniz gerekir (https://github.com/firebase/firebase-jobdispatcher-android). Zamanlanmış hizmeti çalıştırmanızı sağlar. –
Ben 'WindowManager' üzerinde UI elemanları ile bir kenar çubuğu uygulaması var ve ben şimdiye kadar kullandığım görünmez bildirim ile çalışmak gibi görünüyor (görünmez bildirim bir kanal olmadan birdir). Birkaç gün içinde herhangi bir şikayet gelmedi. Emulator, 5 saniye içinde hizmetimi durdurmuyor – prom85