mirror of
https://github.com/androidx/media.git
synced 2025-05-11 09:39:52 +08:00
Add DownloadService constructor for notification channel
Also move NotificationUtil from the UI module to the core module. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=193941401
This commit is contained in:
parent
79c105be59
commit
ddd603a1ee
@ -28,8 +28,8 @@ import com.google.android.exoplayer2.source.dash.offline.DashDownloadAction;
|
||||
import com.google.android.exoplayer2.source.hls.offline.HlsDownloadAction;
|
||||
import com.google.android.exoplayer2.source.smoothstreaming.offline.SsDownloadAction;
|
||||
import com.google.android.exoplayer2.ui.DownloadNotificationUtil;
|
||||
import com.google.android.exoplayer2.ui.NotificationUtil;
|
||||
import com.google.android.exoplayer2.util.ErrorMessageProvider;
|
||||
import com.google.android.exoplayer2.util.NotificationUtil;
|
||||
|
||||
/** A service for downloading media. */
|
||||
public class DemoDownloadService extends DownloadService {
|
||||
@ -41,17 +41,11 @@ public class DemoDownloadService extends DownloadService {
|
||||
private static DownloadManager downloadManager;
|
||||
|
||||
public DemoDownloadService() {
|
||||
super(FOREGROUND_NOTIFICATION_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
NotificationUtil.createNotificationChannel(
|
||||
this,
|
||||
super(
|
||||
FOREGROUND_NOTIFICATION_ID,
|
||||
DEFAULT_FOREGROUND_NOTIFICATION_UPDATE_INTERVAL,
|
||||
CHANNEL_ID,
|
||||
R.string.exo_download_notification_channel_name,
|
||||
NotificationUtil.IMPORTANCE_LOW);
|
||||
super.onCreate();
|
||||
R.string.exo_download_notification_channel_name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -107,7 +107,7 @@ public final class DownloadManager {
|
||||
public DownloadManager(
|
||||
Cache cache,
|
||||
DataSource.Factory upstreamDataSourceFactory,
|
||||
String actionSaveFile,
|
||||
File actionSaveFile,
|
||||
Deserializer... deserializers) {
|
||||
this(
|
||||
new DownloaderConstructorHelper(cache, upstreamDataSourceFactory),
|
||||
|
@ -23,11 +23,13 @@ import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.Looper;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.util.Log;
|
||||
import com.google.android.exoplayer2.offline.DownloadManager.DownloadState;
|
||||
import com.google.android.exoplayer2.scheduler.Requirements;
|
||||
import com.google.android.exoplayer2.scheduler.RequirementsWatcher;
|
||||
import com.google.android.exoplayer2.scheduler.Scheduler;
|
||||
import com.google.android.exoplayer2.util.NotificationUtil;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import java.io.IOException;
|
||||
|
||||
@ -69,6 +71,8 @@ public abstract class DownloadService extends Service {
|
||||
private static Scheduler scheduler;
|
||||
|
||||
private final ForegroundNotificationUpdater foregroundNotificationUpdater;
|
||||
private final @Nullable String channelId;
|
||||
private final @StringRes int channelName;
|
||||
|
||||
private DownloadManager downloadManager;
|
||||
private DownloadListener downloadListener;
|
||||
@ -94,9 +98,37 @@ public abstract class DownloadService extends Service {
|
||||
*/
|
||||
protected DownloadService(
|
||||
int foregroundNotificationId, long foregroundNotificationUpdateInterval) {
|
||||
this(
|
||||
foregroundNotificationId,
|
||||
foregroundNotificationUpdateInterval,
|
||||
/* channelId= */ null,
|
||||
/* channelName= */ 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a DownloadService.
|
||||
*
|
||||
* @param foregroundNotificationId The notification id for the foreground notification, must not
|
||||
* be 0.
|
||||
* @param foregroundNotificationUpdateInterval The maximum interval to update foreground
|
||||
* notification, in milliseconds.
|
||||
* @param channelId An id for a low priority notification channel to create, or {@code null} if
|
||||
* the app will take care of creating a notification channel if needed. If specified, must be
|
||||
* unique per package and the value may be truncated if it is too long.
|
||||
* @param channelName A string resource identifier for the user visible name of the channel, if
|
||||
* {@code channelId} is specified. The recommended maximum length is 40 characters; the value
|
||||
* may be truncated if it is too long.
|
||||
*/
|
||||
protected DownloadService(
|
||||
int foregroundNotificationId,
|
||||
long foregroundNotificationUpdateInterval,
|
||||
@Nullable String channelId,
|
||||
@StringRes int channelName) {
|
||||
foregroundNotificationUpdater =
|
||||
new ForegroundNotificationUpdater(
|
||||
foregroundNotificationId, foregroundNotificationUpdateInterval);
|
||||
this.channelId = channelId;
|
||||
this.channelName = channelName;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -132,10 +164,13 @@ public abstract class DownloadService extends Service {
|
||||
@Override
|
||||
public void onCreate() {
|
||||
logd("onCreate");
|
||||
if (channelId != null) {
|
||||
NotificationUtil.createNotificationChannel(
|
||||
this, channelId, channelName, NotificationUtil.IMPORTANCE_LOW);
|
||||
}
|
||||
downloadManager = getDownloadManager();
|
||||
downloadListener = new DownloadListener();
|
||||
downloadManager.addListener(downloadListener);
|
||||
|
||||
if (requirementsWatcher == null) {
|
||||
Requirements requirements = getRequirements();
|
||||
if (requirements != null) {
|
||||
|
@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.google.android.exoplayer2.ui;
|
||||
package com.google.android.exoplayer2.util;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Notification;
|
||||
@ -24,7 +24,6 @@ import android.content.Intent;
|
||||
import android.support.annotation.IntDef;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
@ -42,6 +42,7 @@ import com.google.android.exoplayer2.PlaybackParameters;
|
||||
import com.google.android.exoplayer2.Player;
|
||||
import com.google.android.exoplayer2.Timeline;
|
||||
import com.google.android.exoplayer2.util.Assertions;
|
||||
import com.google.android.exoplayer2.util.NotificationUtil;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.util.ArrayList;
|
||||
|
Loading…
x
Reference in New Issue
Block a user