Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
fd24df3b
authored
Feb 11, 2020
by
olly
Committed by
Oliver Woodman
Feb 13, 2020
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Fix demo app download notification
PiperOrigin-RevId: 294503035
parent
62092e66
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
13 deletions
demos/main/src/main/java/com/google/android/exoplayer2/demo/DemoApplication.java
demos/main/src/main/java/com/google/android/exoplayer2/demo/DemoDownloadService.java
demos/main/src/main/java/com/google/android/exoplayer2/demo/DemoApplication.java
View file @
fd24df3b
...
@@ -25,6 +25,7 @@ import com.google.android.exoplayer2.offline.DefaultDownloadIndex;
...
@@ -25,6 +25,7 @@ import com.google.android.exoplayer2.offline.DefaultDownloadIndex;
import
com.google.android.exoplayer2.offline.DefaultDownloaderFactory
;
import
com.google.android.exoplayer2.offline.DefaultDownloaderFactory
;
import
com.google.android.exoplayer2.offline.DownloadManager
;
import
com.google.android.exoplayer2.offline.DownloadManager
;
import
com.google.android.exoplayer2.offline.DownloaderConstructorHelper
;
import
com.google.android.exoplayer2.offline.DownloaderConstructorHelper
;
import
com.google.android.exoplayer2.ui.DownloadNotificationHelper
;
import
com.google.android.exoplayer2.upstream.DataSource
;
import
com.google.android.exoplayer2.upstream.DataSource
;
import
com.google.android.exoplayer2.upstream.DefaultDataSourceFactory
;
import
com.google.android.exoplayer2.upstream.DefaultDataSourceFactory
;
import
com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory
;
import
com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory
;
...
@@ -45,6 +46,8 @@ import java.io.IOException;
...
@@ -45,6 +46,8 @@ import java.io.IOException;
*/
*/
public
class
DemoApplication
extends
Application
{
public
class
DemoApplication
extends
Application
{
public
static
final
String
DOWNLOAD_NOTIFICATION_CHANNEL_ID
=
"download_channel"
;
private
static
final
String
TAG
=
"DemoApplication"
;
private
static
final
String
TAG
=
"DemoApplication"
;
private
static
final
String
DOWNLOAD_ACTION_FILE
=
"actions"
;
private
static
final
String
DOWNLOAD_ACTION_FILE
=
"actions"
;
private
static
final
String
DOWNLOAD_TRACKER_ACTION_FILE
=
"tracked_actions"
;
private
static
final
String
DOWNLOAD_TRACKER_ACTION_FILE
=
"tracked_actions"
;
...
@@ -57,6 +60,7 @@ public class DemoApplication extends Application {
...
@@ -57,6 +60,7 @@ public class DemoApplication extends Application {
private
Cache
downloadCache
;
private
Cache
downloadCache
;
private
DownloadManager
downloadManager
;
private
DownloadManager
downloadManager
;
private
DownloadTracker
downloadTracker
;
private
DownloadTracker
downloadTracker
;
private
DownloadNotificationHelper
downloadNotificationHelper
;
@Override
@Override
public
void
onCreate
()
{
public
void
onCreate
()
{
...
@@ -93,6 +97,14 @@ public class DemoApplication extends Application {
...
@@ -93,6 +97,14 @@ public class DemoApplication extends Application {
.
setExtensionRendererMode
(
extensionRendererMode
);
.
setExtensionRendererMode
(
extensionRendererMode
);
}
}
public
DownloadNotificationHelper
getDownloadNotificationHelper
()
{
if
(
downloadNotificationHelper
==
null
)
{
downloadNotificationHelper
=
new
DownloadNotificationHelper
(
this
,
DOWNLOAD_NOTIFICATION_CHANNEL_ID
);
}
return
downloadNotificationHelper
;
}
public
DownloadManager
getDownloadManager
()
{
public
DownloadManager
getDownloadManager
()
{
initDownloadManager
();
initDownloadManager
();
return
downloadManager
;
return
downloadManager
;
...
...
demos/main/src/main/java/com/google/android/exoplayer2/demo/DemoDownloadService.java
View file @
fd24df3b
...
@@ -15,6 +15,8 @@
...
@@ -15,6 +15,8 @@
*/
*/
package
com
.
google
.
android
.
exoplayer2
.
demo
;
package
com
.
google
.
android
.
exoplayer2
.
demo
;
import
static
com
.
google
.
android
.
exoplayer2
.
demo
.
DemoApplication
.
DOWNLOAD_NOTIFICATION_CHANNEL_ID
;
import
android.app.Notification
;
import
android.app.Notification
;
import
android.content.Context
;
import
android.content.Context
;
import
com.google.android.exoplayer2.offline.Download
;
import
com.google.android.exoplayer2.offline.Download
;
...
@@ -29,35 +31,29 @@ import java.util.List;
...
@@ -29,35 +31,29 @@ import java.util.List;
/** A service for downloading media. */
/** A service for downloading media. */
public
class
DemoDownloadService
extends
DownloadService
{
public
class
DemoDownloadService
extends
DownloadService
{
private
static
final
String
CHANNEL_ID
=
"download_channel"
;
private
static
final
int
JOB_ID
=
1
;
private
static
final
int
JOB_ID
=
1
;
private
static
final
int
FOREGROUND_NOTIFICATION_ID
=
1
;
private
static
final
int
FOREGROUND_NOTIFICATION_ID
=
1
;
private
DownloadNotificationHelper
notificationHelper
;
public
DemoDownloadService
()
{
public
DemoDownloadService
()
{
super
(
super
(
FOREGROUND_NOTIFICATION_ID
,
FOREGROUND_NOTIFICATION_ID
,
DEFAULT_FOREGROUND_NOTIFICATION_UPDATE_INTERVAL
,
DEFAULT_FOREGROUND_NOTIFICATION_UPDATE_INTERVAL
,
CHANNEL_ID
,
DOWNLOAD_NOTIFICATION_
CHANNEL_ID
,
R
.
string
.
exo_download_notification_channel_name
,
R
.
string
.
exo_download_notification_channel_name
,
/* channelDescriptionResourceId= */
0
);
/* channelDescriptionResourceId= */
0
);
}
}
@Override
@Override
public
void
onCreate
()
{
super
.
onCreate
();
notificationHelper
=
new
DownloadNotificationHelper
(
this
,
CHANNEL_ID
);
}
@Override
protected
DownloadManager
getDownloadManager
()
{
protected
DownloadManager
getDownloadManager
()
{
DownloadManager
downloadManager
=
((
DemoApplication
)
getApplication
()).
getDownloadManager
();
// This will only happen once, because getDownloadManager is guaranteed to be called only once
// This will only happen once, because getDownloadManager is guaranteed to be called only once
// in the life cycle of the process.
// in the life cycle of the process.
DemoApplication
application
=
(
DemoApplication
)
getApplication
();
DownloadManager
downloadManager
=
application
.
getDownloadManager
();
DownloadNotificationHelper
downloadNotificationHelper
=
application
.
getDownloadNotificationHelper
();
downloadManager
.
addListener
(
downloadManager
.
addListener
(
new
TerminalStateNotificationHelper
(
new
TerminalStateNotificationHelper
(
this
,
n
otificationHelper
,
FOREGROUND_NOTIFICATION_ID
+
1
));
this
,
downloadN
otificationHelper
,
FOREGROUND_NOTIFICATION_ID
+
1
));
return
downloadManager
;
return
downloadManager
;
}
}
...
@@ -68,7 +64,9 @@ public class DemoDownloadService extends DownloadService {
...
@@ -68,7 +64,9 @@ public class DemoDownloadService extends DownloadService {
@Override
@Override
protected
Notification
getForegroundNotification
(
List
<
Download
>
downloads
)
{
protected
Notification
getForegroundNotification
(
List
<
Download
>
downloads
)
{
return
notificationHelper
.
buildProgressNotification
(
return
((
DemoApplication
)
getApplication
())
.
getDownloadNotificationHelper
()
.
buildProgressNotification
(
R
.
drawable
.
ic_download
,
/* contentIntent= */
null
,
/* message= */
null
,
downloads
);
R
.
drawable
.
ic_download
,
/* contentIntent= */
null
,
/* message= */
null
,
downloads
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment