koush/ion — pull request #340 by Swisyn (2014-08-22 09:54:10+00:00)
Title: Download with notification progress

Is there a way to show download progress in notification bar?

I've tried like;

final NotificationManager mNotifyManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
final Builder mBuilder = new NotificationCompat.Builder(context);
mBuilder.setContentTitle(context.getString(R.string.sound_download))
.setContentText(context.getString(R.string.download_in_progress))
.setSmallIcon(R.drawable.ic_refresh);

Ion.with(context).load(url).progressDialog(null)
.progress(new ProgressCallback() {
@Override
public void onProgress(long downloaded, long total) {
android.util.Log.d("progress",
String.valueOf((int) ((downloaded * 100) / total)));
mBuilder.setProgress((int) total, (int) ((downloaded * 100) / total), false);
// Displays the progress bar for the first time.
mNotifyManager.notify(id, mBuilder.build());

}
}).write(musicFile).setCallback(new FutureCallback() {
@Override
public void onCompleted(Exception e, File file) {
mBuilder.setContentText(context.getString(R.string.download_completed))
.setProgress(0, 0, false);
mNotifyManager.notify(id, mBuilder.build());
}
});

but it shows directly download completed message.