version:1.0.4

fix:
update:增加下载
This commit is contained in:
2025-12-15 09:36:54 +08:00
parent 3124840575
commit 3f83d1b136
60 changed files with 2729 additions and 351 deletions

View File

@@ -48,6 +48,7 @@ public class DownloadService extends Service {
mNotificationManagerCompat = NotificationManagerCompat.from(this);
createNotificationChannel();
createDownloadNotificationChannel();
}
@Override
@@ -63,9 +64,9 @@ public class DownloadService extends Service {
private static final String CHANNEL_ID = "CHANNEL_ID";
private static final String CHANNEL_NAME = "系统通知";
private static final String CHANNEL_DESCRIPTION = "关怀桌面通知";
private static final String CHANNEL_DESCRIPTION = "学王365通知";
private static final String CHANNEL_DOWNLOAD = "DOWNLOAD_CHANNEL";
private static final String CHANNEL_DOWNLOAD_ID = "DOWNLOAD_CHANNEL";
private static final String CHANNEL_DOWNLOAD_NAME = "下载管理";
private static final String CHANNEL_DOWNLOAD_DESCRIPTION = "下载管理通知";
@@ -73,11 +74,8 @@ public class DownloadService extends Service {
// Create the NotificationChannel, but only on API 26+ because
// the NotificationChannel class is new and not in the support library
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = CHANNEL_NAME;
String description = CHANNEL_DESCRIPTION;
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
channel.setDescription(description);
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT);
channel.setDescription(CHANNEL_DESCRIPTION);
// Register the channel with the system; you can't change the importance
// or other notification behaviors after this
NotificationManager notificationManager = getSystemService(NotificationManager.class);
@@ -92,7 +90,7 @@ public class DownloadService extends Service {
Intent intent = new Intent(this, DownloadService.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "CHANNEL_ID")
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("关怀系统正在运行")
// .setContentText("测试内容")
@@ -107,8 +105,21 @@ public class DownloadService extends Service {
startForeground(NotificationID, builder.build());
}
private void createDownloadNotificationChannel() {
// Create the NotificationChannel, but only on API 26+ because
// the NotificationChannel class is new and not in the support library
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(CHANNEL_DOWNLOAD_ID, CHANNEL_DOWNLOAD_NAME, NotificationManager.IMPORTANCE_DEFAULT);
channel.setDescription(CHANNEL_DOWNLOAD_DESCRIPTION);
// Register the channel with the system; you can't change the importance
// or other notification behaviors after this
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
}
private void sendDownloadRunning(AriaDownloadInfo ariaDownloadInfo, int progress) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_DOWNLOAD)
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_DOWNLOAD_ID)
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
.setContentTitle(ariaDownloadInfo.getAppName())
@@ -120,11 +131,12 @@ public class DownloadService extends Service {
.setProgress(100, progress, false)
.setPriority(NotificationCompat.PRIORITY_HIGH);
// notificationId is a unique int for each notification that you must define
mNotificationManagerCompat.notify(ariaDownloadInfo.getAppId(), builder.build());
// mNotificationManagerCompat.notify(ariaDownloadInfo.getAppId(), builder.build());
startForeground(ariaDownloadInfo.getAppId(), builder.build());
}
private void sendDownloadComplete(AriaDownloadInfo ariaDownloadInfo, String path) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_DOWNLOAD)
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_DOWNLOAD_ID)
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
.setContentTitle(ariaDownloadInfo.getAppName())
@@ -163,7 +175,7 @@ public class DownloadService extends Service {
}
private void sendDownloadFail(AriaDownloadInfo ariaDownloadInfo) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_DOWNLOAD)
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_DOWNLOAD_ID)
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
.setContentTitle(ariaDownloadInfo.getAppName())