use of com.google.android.exoplayer2.offline.DownloadManager in project ExoPlayer by google.
the class DemoDownloadService method getDownloadManager.
@Override
protected DownloadManager getDownloadManager() {
// This will only happen once, because getDownloadManager is guaranteed to be called only once
// in the life cycle of the process.
DownloadManager downloadManager = DemoUtil.getDownloadManager(/* context= */
this);
DownloadNotificationHelper downloadNotificationHelper = DemoUtil.getDownloadNotificationHelper(/* context= */
this);
downloadManager.addListener(new TerminalStateNotificationHelper(this, downloadNotificationHelper, FOREGROUND_NOTIFICATION_ID + 1));
return downloadManager;
}
use of com.google.android.exoplayer2.offline.DownloadManager in project ExoPlayer by google.
the class DownloadService method onCreate.
@Override
public void onCreate() {
if (channelId != null) {
NotificationUtil.createNotificationChannel(this, channelId, channelNameResourceId, channelDescriptionResourceId, NotificationUtil.IMPORTANCE_LOW);
}
Class<? extends DownloadService> clazz = getClass();
@Nullable DownloadManagerHelper downloadManagerHelper = downloadManagerHelpers.get(clazz);
if (downloadManagerHelper == null) {
boolean foregroundAllowed = foregroundNotificationUpdater != null;
// See https://developer.android.com/about/versions/12/foreground-services.
boolean canStartForegroundServiceFromBackground = Util.SDK_INT < 31;
@Nullable Scheduler scheduler = foregroundAllowed && canStartForegroundServiceFromBackground ? getScheduler() : null;
DownloadManager downloadManager = getDownloadManager();
downloadManager.resumeDownloads();
downloadManagerHelper = new DownloadManagerHelper(getApplicationContext(), downloadManager, foregroundAllowed, scheduler, clazz);
downloadManagerHelpers.put(clazz, downloadManagerHelper);
}
this.downloadManagerHelper = downloadManagerHelper;
downloadManagerHelper.attachService(this);
}
Aggregations