@@ -155,7 +155,7 @@ private void downloadApk() {
155
155
String channelId = "" ;
156
156
// 适配 Android 8.0 通知渠道新特性
157
157
if (android .os .Build .VERSION .SDK_INT >= android .os .Build .VERSION_CODES .O ) {
158
- NotificationChannel channel = new NotificationChannel (getString (R .string .update_notification_channel_id ), getString (R .string .update_notification_channel_name ), NotificationManager .IMPORTANCE_HIGH );
158
+ NotificationChannel channel = new NotificationChannel (getString (R .string .update_notification_channel_id ), getString (R .string .update_notification_channel_name ), NotificationManager .IMPORTANCE_LOW );
159
159
channel .enableLights (false );
160
160
channel .enableVibration (false );
161
161
channel .setVibrationPattern (new long []{0 });
@@ -165,6 +165,7 @@ private void downloadApk() {
165
165
}
166
166
167
167
NotificationCompat .Builder notificationBuilder = new NotificationCompat .Builder (getContext (), channelId )
168
+ // 设置通知时间
168
169
.setWhen (System .currentTimeMillis ())
169
170
// 设置通知标题
170
171
.setContentTitle (getString (R .string .app_name ))
@@ -174,7 +175,9 @@ private void downloadApk() {
174
175
.setLargeIcon (BitmapFactory .decodeResource (getResources (), R .mipmap .launcher_ic ))
175
176
// 设置通知静音
176
177
.setDefaults (NotificationCompat .FLAG_ONLY_ALERT_ONCE )
178
+ // 设置震动频率
177
179
.setVibrate (new long []{0 })
180
+ // 设置声音文件
178
181
.setSound (null )
179
182
// 设置通知的优先级
180
183
.setPriority (NotificationCompat .PRIORITY_DEFAULT );
@@ -204,6 +207,8 @@ public void onStart(File file) {
204
207
205
208
@ Override
206
209
public void onProgress (File file , int progress ) {
210
+ mUpdateView .setText (String .format (getString (R .string .update_status_running ), progress ));
211
+ mProgressView .setProgress (progress );
207
212
// 更新下载通知
208
213
notificationManager .notify (notificationId , notificationBuilder
209
214
// 设置通知的文本
@@ -212,10 +217,10 @@ public void onProgress(File file, int progress) {
212
217
.setProgress (100 , progress , false )
213
218
// 设置点击通知后是否自动消失
214
219
.setAutoCancel (false )
220
+ // 是否正在交互中
221
+ .setOngoing (true )
215
222
// 重新创建新的通知对象
216
223
.build ());
217
- mUpdateView .setText (String .format (getString (R .string .update_status_running ), progress ));
218
- mProgressView .setProgress (progress );
219
224
}
220
225
221
226
@ Override
@@ -230,6 +235,8 @@ public void onComplete(File file) {
230
235
.setContentIntent (PendingIntent .getActivity (getContext (), 1 , getInstallIntent (), Intent .FILL_IN_ACTION ))
231
236
// 设置点击通知后是否自动消失
232
237
.setAutoCancel (true )
238
+ // 是否正在交互中
239
+ .setOngoing (false )
233
240
.build ());
234
241
mUpdateView .setText (R .string .update_status_successful );
235
242
// 标记成下载完成
0 commit comments