diff --git a/app/src/main/java/gr/thmmy/mthmmy/receiver/Receiver.java b/app/src/main/java/gr/thmmy/mthmmy/receiver/Receiver.java index 2ef4fdd4..a36916ea 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/receiver/Receiver.java +++ b/app/src/main/java/gr/thmmy/mthmmy/receiver/Receiver.java @@ -29,8 +29,7 @@ import static gr.thmmy.mthmmy.services.DownloadService.STARTED; public class Receiver extends BroadcastReceiver { - public Receiver() { - } + public Receiver() {} @Override public void onReceive(Context context, Intent intent) { @@ -48,11 +47,11 @@ public class Receiver extends BroadcastReceiver { builder.setContentTitle(title) .setContentText(text) .setTicker(ticker) - .setAutoCancel(true) - .setSmallIcon(R.drawable.ic_file_download); + .setAutoCancel(true); if (state.equals(STARTED)) - builder.setOngoing(true); + builder.setOngoing(true) + .setSmallIcon(android.R.drawable.stat_sys_download); else if (state.equals(COMPLETED)) { String fileName = extras.getString(EXTRA_FILE_NAME, "NONE"); @@ -68,7 +67,8 @@ public class Receiver extends BroadcastReceiver { Intent chooser = Intent.createChooser(chooserIntent, "Open With..."); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, chooser, PendingIntent.FLAG_CANCEL_CURRENT); - builder.setContentIntent(pendingIntent); + builder.setContentIntent(pendingIntent) + .setSmallIcon(android.R.drawable.stat_sys_download_done); } else Timber.w("File doesn't exist."); diff --git a/app/src/main/java/gr/thmmy/mthmmy/services/DownloadService.java b/app/src/main/java/gr/thmmy/mthmmy/services/DownloadService.java index 4e22c7b1..c14387f1 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/services/DownloadService.java +++ b/app/src/main/java/gr/thmmy/mthmmy/services/DownloadService.java @@ -106,9 +106,9 @@ public class DownloadService extends IntentService { Request request = new Request.Builder().url(downloadLink).build(); Response response = client.newCall(request).execute(); - String contentType = response.headers("Content-Type").toString(); //check if link provides a binary file - if (contentType.equals("[application/octet-stream]")) { - fileName = response.headers("Content-Disposition").toString().split("\"")[1]; + String contentDisposition = response.headers("Content-Disposition").toString(); //check if link provides an attachment + if (contentDisposition.contains("attachment")){ + fileName = contentDisposition.split("\"")[1]; File dirPath = new File(SAVE_DIR); if (!dirPath.isDirectory()) { @@ -150,7 +150,7 @@ public class DownloadService extends IntentService { Timber.i("Download OK!"); sendNotification(downloadId, COMPLETED, fileName); } else - Timber.e("Response not a binary file!"); + Timber.e("No attachment in response!"); } catch (FileNotFoundException e) { Timber.i("Download failed..."); Timber.e(e, "FileNotFound"); diff --git a/app/src/main/res/drawable/ic_file_download.xml b/app/src/main/res/drawable/ic_file_download.xml deleted file mode 100644 index 80734766..00000000 --- a/app/src/main/res/drawable/ic_file_download.xml +++ /dev/null @@ -1,9 +0,0 @@ - - -