|
|
@ -59,8 +59,12 @@ class DownloadService : BaseService() { |
|
|
|
) |
|
|
|
) |
|
|
|
IntentAction.play -> { |
|
|
|
IntentAction.play -> { |
|
|
|
val id = intent.getLongExtra("downloadId", 0) |
|
|
|
val id = intent.getLongExtra("downloadId", 0) |
|
|
|
if (downloads[id]?.endsWith(".apk") == true) { |
|
|
|
if (completeDownloads.contains(id) |
|
|
|
|
|
|
|
&& downloads[id]?.endsWith(".apk") == true |
|
|
|
|
|
|
|
) { |
|
|
|
installApk(id) |
|
|
|
installApk(id) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
toastOnUi("下载的文件在Download文件夹") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
IntentAction.stop -> { |
|
|
|
IntentAction.stop -> { |
|
|
@ -160,14 +164,7 @@ class DownloadService : BaseService() { |
|
|
|
.setSmallIcon(R.drawable.ic_download) |
|
|
|
.setSmallIcon(R.drawable.ic_download) |
|
|
|
.setOngoing(true) |
|
|
|
.setOngoing(true) |
|
|
|
.setContentTitle(getString(R.string.action_download)) |
|
|
|
.setContentTitle(getString(R.string.action_download)) |
|
|
|
notificationBuilder.addAction( |
|
|
|
.setGroup(groupKey) |
|
|
|
R.drawable.ic_stop_black_24dp, |
|
|
|
|
|
|
|
getString(R.string.cancel), |
|
|
|
|
|
|
|
servicePendingIntent<DownloadService>(IntentAction.stop) { |
|
|
|
|
|
|
|
putExtra("downloadId", -1) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
notificationBuilder.setGroup(groupKey) |
|
|
|
|
|
|
|
.setGroupSummary(true) |
|
|
|
.setGroupSummary(true) |
|
|
|
val notification = notificationBuilder.build() |
|
|
|
val notification = notificationBuilder.build() |
|
|
|
startForeground(summaryId, notification) |
|
|
|
startForeground(summaryId, notification) |
|
|
@ -179,29 +176,28 @@ class DownloadService : BaseService() { |
|
|
|
private fun updateNotification(downloadId: Long, content: String, max: Int, progress: Int) { |
|
|
|
private fun updateNotification(downloadId: Long, content: String, max: Int, progress: Int) { |
|
|
|
val notificationBuilder = NotificationCompat.Builder(this, AppConst.channelIdDownload) |
|
|
|
val notificationBuilder = NotificationCompat.Builder(this, AppConst.channelIdDownload) |
|
|
|
.setSmallIcon(R.drawable.ic_download) |
|
|
|
.setSmallIcon(R.drawable.ic_download) |
|
|
|
.setOngoing(true) |
|
|
|
|
|
|
|
.setContentTitle(getString(R.string.action_download)) |
|
|
|
.setContentTitle(getString(R.string.action_download)) |
|
|
|
notificationBuilder.setContentIntent( |
|
|
|
.setContentIntent( |
|
|
|
servicePendingIntent<DownloadService>(IntentAction.play) { |
|
|
|
servicePendingIntent<DownloadService>(IntentAction.play) { |
|
|
|
putExtra("downloadId", downloadId) |
|
|
|
putExtra("downloadId", downloadId) |
|
|
|
} |
|
|
|
} |
|
|
|
) |
|
|
|
) |
|
|
|
notificationBuilder.addAction( |
|
|
|
.addAction( |
|
|
|
R.drawable.ic_stop_black_24dp, |
|
|
|
R.drawable.ic_stop_black_24dp, |
|
|
|
getString(R.string.cancel), |
|
|
|
getString(R.string.cancel), |
|
|
|
servicePendingIntent<DownloadService>(IntentAction.stop) { |
|
|
|
servicePendingIntent<DownloadService>(IntentAction.stop) { |
|
|
|
putExtra("downloadId", downloadId) |
|
|
|
putExtra("downloadId", downloadId) |
|
|
|
} |
|
|
|
} |
|
|
|
) |
|
|
|
) |
|
|
|
notificationBuilder.setDeleteIntent( |
|
|
|
.setDeleteIntent( |
|
|
|
servicePendingIntent<DownloadService>(IntentAction.stop) { |
|
|
|
servicePendingIntent<DownloadService>(IntentAction.stop) { |
|
|
|
putExtra("downloadId", downloadId) |
|
|
|
putExtra("downloadId", downloadId) |
|
|
|
} |
|
|
|
} |
|
|
|
) |
|
|
|
) |
|
|
|
notificationBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) |
|
|
|
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) |
|
|
|
notificationBuilder.setContentText(content) |
|
|
|
.setContentText(content) |
|
|
|
notificationBuilder.setProgress(max, progress, false) |
|
|
|
.setProgress(max, progress, false) |
|
|
|
notificationBuilder.setGroup(groupKey) |
|
|
|
.setGroup(groupKey) |
|
|
|
val notification = notificationBuilder.build() |
|
|
|
val notification = notificationBuilder.build() |
|
|
|
NotificationManagerCompat.from(this).apply { |
|
|
|
NotificationManagerCompat.from(this).apply { |
|
|
|
notify(downloadId.toInt(), notification) |
|
|
|
notify(downloadId.toInt(), notification) |
|
|
|