Skip to content

Commit 6f56881

Browse files
authored
Revert "Ability to display custom notification title on Android (#437)" (#707)
* Revert "Ability to display custom notification title on Android (#437)" This reverts commit 5e80a37. * set version to 1.8.3
1 parent 5960d47 commit 6f56881

File tree

10 files changed

+40
-52
lines changed

10 files changed

+40
-52
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 1.8.3
2+
3+
- Android: revert possibility to set custom notification title introduced in
4+
#437. This fixes #705
5+
16
## 1.8.2
27

38
- Fix crashing on Flutter 3.3 (#700)

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ final taskId = await FlutterDownloader.enqueue(
294294
savedDir: 'the path of directory where you want to save downloaded files',
295295
showNotification: true, // show download progress in status bar (for Android)
296296
openFileFromNotification: true, // click on notification to open downloaded file (for Android)
297-
notificationTitle: 'Notification title', // set title of notification (for Android)
298297
);
299298
```
300299

@@ -382,7 +381,6 @@ CREATE TABLE `task` (
382381
`headers` TEXT,
383382
`show_notification` TINYINT DEFAULT 0,
384383
`open_file_from_notification` TINYINT DEFAULT 0,
385-
`notification_title` TEXT,
386384
`time_created` INTEGER DEFAULT 0
387385
);
388386
```

android/src/main/java/vn/hunghd/flutterdownloader/DownloadTask.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ public class DownloadTask {
1313
boolean resumable;
1414
boolean showNotification;
1515
boolean openFileFromNotification;
16-
String notificationTitle;
1716
long timeCreated;
1817
boolean saveInPublicStorage;
1918

2019
DownloadTask(int primaryId, String taskId, int status, int progress, String url, String filename, String savedDir,
21-
String headers, String mimeType, boolean resumable, boolean showNotification, boolean openFileFromNotification, String notificationTitle, long timeCreated, boolean saveInPublicStorage) {
20+
String headers, String mimeType, boolean resumable, boolean showNotification, boolean openFileFromNotification, long timeCreated, boolean saveInPublicStorage) {
2221
this.primaryId = primaryId;
2322
this.taskId = taskId;
2423
this.status = status;
@@ -31,13 +30,12 @@ public class DownloadTask {
3130
this.resumable = resumable;
3231
this.showNotification = showNotification;
3332
this.openFileFromNotification = openFileFromNotification;
34-
this.notificationTitle = notificationTitle;
3533
this.timeCreated = timeCreated;
3634
this.saveInPublicStorage = saveInPublicStorage;
3735
}
3836

3937
@Override
4038
public String toString() {
41-
return "DownloadTask{taskId=" + taskId + ", status=" + status + ", progress=" + progress + ", url=" + url + ", filename=" + filename + ", savedDir=" + savedDir + ", headers=" + headers + ", notificationTitle=" + notificationTitle + ", saveInPublicStorage= " + saveInPublicStorage + "}";
39+
return "DownloadTask{taskId=" + taskId + ",status=" + status + ",progress=" + progress + ",url=" + url + ",filename=" + filename + ",savedDir=" + savedDir + ",headers=" + headers + ", saveInPublicStorage= " + saveInPublicStorage + "}";
4240
}
4341
}

android/src/main/java/vn/hunghd/flutterdownloader/DownloadWorker.java

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ public class DownloadWorker extends Worker implements MethodChannel.MethodCallHa
7777
public static final String ARG_IS_RESUME = "is_resume";
7878
public static final String ARG_SHOW_NOTIFICATION = "show_notification";
7979
public static final String ARG_OPEN_FILE_FROM_NOTIFICATION = "open_file_from_notification";
80-
public static final String ARG_NOTIFICATION_TITLE = "notification_title";
8180
public static final String ARG_CALLBACK_HANDLE = "callback_handle";
8281
public static final String ARG_DEBUG = "debug";
8382
public static final String ARG_STEP = "step";
@@ -166,11 +165,10 @@ public void onStopped() {
166165

167166
String url = getInputData().getString(ARG_URL);
168167
String filename = getInputData().getString(ARG_FILE_NAME);
169-
String notificationTitle = getInputData().getString(ARG_NOTIFICATION_TITLE);
170168

171169
DownloadTask task = taskDao.loadTask(getId().toString());
172170
if (task != null && task.status == DownloadStatus.ENQUEUED) {
173-
updateNotification(context, filename == null ? url : filename, DownloadStatus.CANCELED, -1, null, true, notificationTitle);
171+
updateNotification(context, filename == null ? url : filename, DownloadStatus.CANCELED, -1, null, true);
174172
taskDao.updateTask(getId().toString(), DownloadStatus.CANCELED, lastProgress);
175173
}
176174
}
@@ -210,32 +208,31 @@ public Result doWork() {
210208

211209
showNotification = getInputData().getBoolean(ARG_SHOW_NOTIFICATION, false);
212210
clickToOpenDownloadedFile = getInputData().getBoolean(ARG_OPEN_FILE_FROM_NOTIFICATION, false);
213-
String notificationTitle = getInputData().getString(ARG_NOTIFICATION_TITLE);
214211
saveInPublicStorage = getInputData().getBoolean(ARG_SAVE_IN_PUBLIC_STORAGE, false);
215212

216213
primaryId = task.primaryId;
217214

218215
setupNotification(context);
219216

220-
updateNotification(context, filename == null ? url : filename, DownloadStatus.RUNNING, task.progress, null, false, notificationTitle);
217+
updateNotification(context, filename == null ? url : filename, DownloadStatus.RUNNING, task.progress, null, false);
221218
taskDao.updateTask(getId().toString(), DownloadStatus.RUNNING, task.progress);
222219

223220
//automatic resume for partial files. (if the workmanager unexpectedly quited in background)
224221
String saveFilePath = savedDir + File.separator + filename;
225222
File partialFile = new File(saveFilePath);
226223
if (partialFile.exists()) {
227224
isResume = true;
228-
log("exists file for " + filename + "automatic resuming...");
225+
log("exists file for "+ filename + "automatic resuming...");
229226
}
230227

231228
try {
232-
downloadFile(context, url, savedDir, filename, notificationTitle, headers, isResume);
229+
downloadFile(context, url, savedDir, filename, headers, isResume);
233230
cleanUp();
234231
dbHelper = null;
235232
taskDao = null;
236233
return Result.success();
237234
} catch (Exception e) {
238-
updateNotification(context, filename == null ? url : filename, DownloadStatus.FAILED, -1, null, true, notificationTitle);
235+
updateNotification(context, filename == null ? url : filename, DownloadStatus.FAILED, -1, null, true);
239236
taskDao.updateTask(getId().toString(), DownloadStatus.FAILED, lastProgress);
240237
e.printStackTrace();
241238
dbHelper = null;
@@ -249,7 +246,7 @@ private void setupHeaders(HttpURLConnection conn, String headers) {
249246
log("Headers = " + headers);
250247
try {
251248
JSONObject json = new JSONObject(headers);
252-
for (Iterator<String> it = json.keys(); it.hasNext();) {
249+
for (Iterator<String> it = json.keys(); it.hasNext(); ) {
253250
String key = it.next();
254251
conn.setRequestProperty(key, json.getString(key));
255252
}
@@ -272,7 +269,7 @@ private long setupPartialDownloadedDataHeader(HttpURLConnection conn, String fil
272269
return downloadedBytes;
273270
}
274271

275-
private void downloadFile(Context context, String fileURL, String savedDir, String filename, String notificationTitle, String headers, boolean isResume) throws IOException {
272+
private void downloadFile(Context context, String fileURL, String savedDir, String filename, String headers, boolean isResume) throws IOException {
276273
String url = fileURL;
277274
URL resourceUrl, base, next;
278275
Map<String, Integer> visited;
@@ -301,14 +298,14 @@ private void downloadFile(Context context, String fileURL, String savedDir, Stri
301298

302299
resourceUrl = new URL(url);
303300

304-
if (ignoreSsl) {
301+
if(ignoreSsl) {
305302
trustAllHosts();
306303
if (resourceUrl.getProtocol().toLowerCase().equals("https")) {
307-
HttpsURLConnection https = (HttpsURLConnection) resourceUrl.openConnection();
304+
HttpsURLConnection https = (HttpsURLConnection)resourceUrl.openConnection();
308305
https.setHostnameVerifier(DO_NOT_VERIFY);
309306
httpConn = https;
310307
} else {
311-
httpConn = (HttpURLConnection) resourceUrl.openConnection();
308+
httpConn = (HttpURLConnection)resourceUrl.openConnection();
312309
}
313310
} else {
314311
httpConn = (HttpsURLConnection) resourceUrl.openConnection();
@@ -317,7 +314,7 @@ private void downloadFile(Context context, String fileURL, String savedDir, Stri
317314
log("Open connection to " + url);
318315
httpConn.setConnectTimeout(15000);
319316
httpConn.setReadTimeout(15000);
320-
httpConn.setInstanceFollowRedirects(false); // Make the logic below easier to detect redirections
317+
httpConn.setInstanceFollowRedirects(false); // Make the logic below easier to detect redirections
321318
httpConn.setRequestProperty("User-Agent", "Mozilla/5.0...");
322319

323320
// setup request headers if it is set
@@ -338,7 +335,7 @@ private void downloadFile(Context context, String fileURL, String savedDir, Stri
338335
location = httpConn.getHeaderField("Location");
339336
log("Location = " + location);
340337
base = new URL(url);
341-
next = new URL(base, location); // Deal with relative URLs
338+
next = new URL(base, location); // Deal with relative URLs
342339
url = next.toExternalForm();
343340
log("New url: " + url);
344341
continue;
@@ -384,6 +381,7 @@ private void downloadFile(Context context, String fileURL, String savedDir, Stri
384381
// opens input stream from the HTTP connection
385382
inputStream = httpConn.getInputStream();
386383

384+
387385
String savedFilePath;
388386
// opens an output stream to save into file
389387
// there are two case:
@@ -427,7 +425,7 @@ private void downloadFile(Context context, String fileURL, String savedDir, Stri
427425
// a new bunch of data fetched and a notification sent
428426
taskDao.updateTask(getId().toString(), DownloadStatus.RUNNING, progress);
429427

430-
updateNotification(context, filename, DownloadStatus.RUNNING, progress, null, false, notificationTitle);
428+
updateNotification(context, filename, DownloadStatus.RUNNING, progress, null, false);
431429
}
432430
}
433431

@@ -457,19 +455,19 @@ private void downloadFile(Context context, String fileURL, String savedDir, Stri
457455
}
458456
}
459457
taskDao.updateTask(getId().toString(), status, progress);
460-
updateNotification(context, filename, status, progress, pendingIntent, true, notificationTitle);
458+
updateNotification(context, filename, status, progress, pendingIntent, true);
461459

462460
log(isStopped() ? "Download canceled" : "File downloaded");
463461
} else {
464462
DownloadTask task = taskDao.loadTask(getId().toString());
465463
int status = isStopped() ? (task.resumable ? DownloadStatus.PAUSED : DownloadStatus.CANCELED) : DownloadStatus.FAILED;
466464
taskDao.updateTask(getId().toString(), status, lastProgress);
467-
updateNotification(context, filename == null ? fileURL : filename, status, -1, null, true, notificationTitle);
465+
updateNotification(context, filename == null ? fileURL : filename, status, -1, null, true);
468466
log(isStopped() ? "Download canceled" : "Server replied HTTP code: " + responseCode);
469467
}
470468
} catch (IOException e) {
471469
taskDao.updateTask(getId().toString(), DownloadStatus.FAILED, lastProgress);
472-
updateNotification(context, filename == null ? fileURL : filename, DownloadStatus.FAILED, -1, null, true, notificationTitle);
470+
updateNotification(context, filename == null ? fileURL : filename, DownloadStatus.FAILED, -1, null, true);
473471
e.printStackTrace();
474472
} finally {
475473
if (outputStream != null) {
@@ -538,10 +536,11 @@ private Uri createFileInPublicDownloadsDir(String filename, String mimeType) {
538536
private String getMediaStoreEntryPathApi29(Uri uri) {
539537
try (Cursor cursor = getApplicationContext().getContentResolver().query(
540538
uri,
541-
new String[] { MediaStore.Files.FileColumns.DATA },
539+
new String[]{MediaStore.Files.FileColumns.DATA},
542540
null,
543541
null,
544-
null)) {
542+
null
543+
)) {
545544
if (cursor == null)
546545
return null;
547546
if (!cursor.moveToFirst())
@@ -557,8 +556,8 @@ private String getMediaStoreEntryPathApi29(Uri uri) {
557556
void scanFilePath(String path, String mimeType, CallbackUri callback) {
558557
MediaScannerConnection.scanFile(
559558
getApplicationContext(),
560-
new String[] { path },
561-
new String[] { mimeType },
559+
new String[]{path},
560+
new String[]{mimeType},
562561
(path1, uri) -> callback.invoke(uri));
563562
}
564563

@@ -609,14 +608,14 @@ private void setupNotification(Context context) {
609608
}
610609
}
611610

612-
private void updateNotification(Context context, String title, int status, int progress, PendingIntent intent, boolean finalize, String notificationTitle) {
611+
private void updateNotification(Context context, String title, int status, int progress, PendingIntent intent, boolean finalize) {
613612
sendUpdateProcessEvent(status, progress);
614613

615614
// Show the notification
616615
if (showNotification) {
617616
// Create the notification
618617
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID).
619-
setContentTitle(notificationTitle == null ? title : notificationTitle)
618+
setContentTitle(title)
620619
.setContentIntent(intent)
621620
.setOnlyAlertOnce(true)
622621
.setAutoCancel(true)

android/src/main/java/vn/hunghd/flutterdownloader/FlutterDownloaderPlugin.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
110110
}
111111

112112
private WorkRequest buildRequest(String url, String savedDir, String filename, String headers,
113-
boolean showNotification, boolean openFileFromNotification, String notificationTitle,
113+
boolean showNotification, boolean openFileFromNotification,
114114
boolean isResume, boolean requiresStorageNotLow, boolean saveInPublicStorage) {
115115
WorkRequest request = new OneTimeWorkRequest.Builder(DownloadWorker.class)
116116
.setConstraints(new Constraints.Builder()
@@ -126,7 +126,6 @@ private WorkRequest buildRequest(String url, String savedDir, String filename, S
126126
.putString(DownloadWorker.ARG_HEADERS, headers)
127127
.putBoolean(DownloadWorker.ARG_SHOW_NOTIFICATION, showNotification)
128128
.putBoolean(DownloadWorker.ARG_OPEN_FILE_FROM_NOTIFICATION, openFileFromNotification)
129-
.putString(DownloadWorker.ARG_NOTIFICATION_TITLE, notificationTitle)
130129
.putBoolean(DownloadWorker.ARG_IS_RESUME, isResume)
131130
.putLong(DownloadWorker.ARG_CALLBACK_HANDLE, callbackHandle)
132131
.putInt(DownloadWorker.ARG_STEP, step)
@@ -173,17 +172,16 @@ private void enqueue(MethodCall call, MethodChannel.Result result) {
173172
String headers = call.argument("headers");
174173
boolean showNotification = call.argument("show_notification");
175174
boolean openFileFromNotification = call.argument("open_file_from_notification");
176-
String notificationTitle = call.argument("notification_title");
177175
boolean requiresStorageNotLow = call.argument("requires_storage_not_low");
178176
boolean saveInPublicStorage = call.argument("save_in_public_storage");
179177
WorkRequest request = buildRequest(url, savedDir, filename, headers, showNotification,
180-
openFileFromNotification, notificationTitle, false, requiresStorageNotLow, saveInPublicStorage);
178+
openFileFromNotification, false, requiresStorageNotLow, saveInPublicStorage);
181179
WorkManager.getInstance(context).enqueue(request);
182180
String taskId = request.getId().toString();
183181
result.success(taskId);
184182
sendUpdateProgress(taskId, DownloadStatus.ENQUEUED, 0);
185183
taskDao.insertOrUpdateNewTask(taskId, url, DownloadStatus.ENQUEUED, 0, filename,
186-
savedDir, headers, showNotification, openFileFromNotification, notificationTitle, saveInPublicStorage);
184+
savedDir, headers, showNotification, openFileFromNotification, saveInPublicStorage);
187185
}
188186

189187
private void loadTasks(MethodCall call, MethodChannel.Result result) {
@@ -257,7 +255,7 @@ private void resume(MethodCall call, MethodChannel.Result result) {
257255
if (partialFile.exists()) {
258256
WorkRequest request = buildRequest(task.url, task.savedDir, task.filename,
259257
task.headers, task.showNotification, task.openFileFromNotification,
260-
task.notificationTitle, true, requiresStorageNotLow, task.saveInPublicStorage);
258+
true, requiresStorageNotLow, task.saveInPublicStorage);
261259
String newTaskId = request.getId().toString();
262260
result.success(newTaskId);
263261
sendUpdateProgress(newTaskId, DownloadStatus.RUNNING, task.progress);
@@ -283,7 +281,7 @@ private void retry(MethodCall call, MethodChannel.Result result) {
283281
if (task.status == DownloadStatus.FAILED || task.status == DownloadStatus.CANCELED) {
284282
WorkRequest request = buildRequest(task.url, task.savedDir, task.filename,
285283
task.headers, task.showNotification, task.openFileFromNotification,
286-
task.notificationTitle, false, requiresStorageNotLow, task.saveInPublicStorage);
284+
false, requiresStorageNotLow, task.saveInPublicStorage);
287285
String newTaskId = request.getId().toString();
288286
result.success(newTaskId);
289287
sendUpdateProgress(newTaskId, DownloadStatus.ENQUEUED, task.progress);

android/src/main/java/vn/hunghd/flutterdownloader/TaskContract.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public static class TaskEntry implements BaseColumns {
1919
public static final String COLUMN_NAME_HEADERS = "headers";
2020
public static final String COLUMN_NAME_SHOW_NOTIFICATION = "show_notification";
2121
public static final String COLUMN_NAME_OPEN_FILE_FROM_NOTIFICATION = "open_file_from_notification";
22-
public static final String COLUMN_NAME_NOTIFICATION_TITLE = "notification_title";
2322
public static final String COLUMN_NAME_TIME_CREATED = "time_created";
2423
public static final String COLUMN_SAVE_IN_PUBLIC_STORAGE = "save_in_public_storage";
2524
}

0 commit comments

Comments
 (0)