Display progress bar in Cordova local notification

I use this great plugin https://github.com/katzer/cordova-plugin-local-notifications to implement local notifications when downloading files. I did not find how to display in the notification Progress bar, such as in this machine http://javatechig.com/wp-content/uploads/2014/05/Displaying-Progress-Notification-in-Android-Example.png
Can you help me?
use the plug-in cordova-file-Transfer and make the following changes:

You can Change the plugin for the Android platform in this way.

Use the following code to create the class FileProgressBarTask:

package org.apache.cordova.filetransfer;

import android.app.NotificationManager;
import android.os.AsyncTask;
import android.support.v4.app.NotificationCompat;
import android.util.Log;< br />
class FileProgressBarTask extends AsyncTask {

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());
}
}

Use the following code to change the class FileTransfer:

< /p>

import a ndroid.content.res.Resources;
import android.content.Context;
import android.app.NotificationManager;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.Builder;

~700 lines in the method download of 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, mNotificationMana ger, id);

In the method download, find the block code containing the following content: while and progress.setLoaded(inputStream.getTotalRawBytesRead()); in the method download, insert the following code:

long lng = Math.abs((progress.getLoaded() / 100) / 100);
progressBarTask.onProgressUpdate(Integer.parseInt(String.valueOf(lng))) ;

Based on:

> Progress Notification in Android Example
> javatechig/Progress-Notification-Example-Android

I use this great plugin https://github.com/katzer/cordova-plugin-local-notifications to implement local notifications when downloading files. I didn’t find how to display the progress bar in the notification, as in this machine http:/ /javatechig.com/wp-content/uploads/2014/05/Displaying-Progress-Notification-in-Android-Example.png
Can you help me?

Use the plug-in cordova-file-Transfer and make the following changes:

You can change the plug-in for the Android platform in this way.

p>

Use the following code to create the class FileProgressBarTask:

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()) ;
}
}

Use the following code to change the class FileTransfer:

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;

In the method download of the FileTransfer class~700 lines:

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 that contains the following content in the method download: while and progress.setLoad ed(inputStream.getTotalRawBytesRead());In the method download, insert the following code:

long lng = Math.abs((progress.getLoaded() / 100) / 100 );
progressBarTask.onProgressUpdate(Integer.parseInt(String.valueOf(lng)));

Based on:

> Progress Notification in Android Example
> javatechig /Progress-Notification-Example-Android

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3780 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.