Use the cordova-file-Transfer plugin and make the following changes:
You can change the plugin this way for the Android platform.
Create a FileProgressBarTask class with the following code:
package org.apache.cordova.filetransfer; import android.app.NotificationManager; import android.os.AsyncTask; import android.support.v4.app.NotificationCompat; import android.util.Log; class FileProgressBarTask extends AsyncTask<Void, Integer, Integer> { private NotificationCompat.Builder mBuilder; private NotificationManager mNotificationManager; int id = 0; int progress = 0; FileProgressBarTask(NotificationCompat.Builder mBuilder, NotificationManager mNotificationManager, int id){ Log.d("TAG", "Progress Bar"); this.mBuilder = mBuilder; this.mNotificationManager = mNotificationManager; this.id = id; super.execute(); } @Override protected void onPreExecute(){ super.onPreExecute(); mBuilder.setProgress(150, 0, false); mNotificationManager.notify(id, mBuilder.build()); } @Override protected void onProgressUpdate(Integer... values){ mBuilder.setProgress(150, values[0], false); mNotificationManager.notify(id, mBuilder.build()); super.onProgressUpdate(values); } @Override protected Integer doInBackground(Void... params) { return null; } @Override protected void onPostExecute(Integer result){ super.onPostExecute(result); mBuilder.setContentText("Download ConcluΓdo"); mBuilder.setProgress(0, 0, false); mNotificationManager.notify(id, mBuilder.build()); } }
Change the FileTransfer class to the following code:
import android.content.res.Resources; import android.content.Context; import android.app.NotificationManager; import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat.Builder;
At line ~ 700, download the method in the FileTransfer class:
Context contextApplication = cordova.getActivity().getApplicationContext(); Resources resources = contextApplication.getResources(); String pkgName = contextApplication.getPackageName(); int resId = resources.getIdentifier("ic_action_download", "drawable", pkgName); mNotificationManager = (NotificationManager) cordova.getActivity().getSystemService(Context.NOTIFICATION_SERVICE); mBuilder = new NotificationCompat.Builder(cordova.getActivity()); mBuilder.setContentTitle("Download File") .setContentText("Progress") .setSmallIcon(resId); final FileProgressBarTask progressBarTask = new FileProgressBarTask(mBuilder, mNotificationManager, id);
Find the block code in the load method, which contains: while and progress.setLoaded(inputStream.getTotalRawBytesRead()); when loading the method, enter the following code:
long lng = Math.abs((progress.getLoaded() / 100) / 100); progressBarTask.onProgressUpdate(Integer.parseInt(String.valueOf(lng)));
Based: