2014-09-01 7 views
5

Ich verwende dieses große Plugin https://github.com/katzer/cordova-plugin-local-notifications, um lokale Benachrichtigung beim Herunterladen einer Datei zu implementieren. Ich finde nicht, wie man eine Fortschrittsbalken in der Benachrichtigung wie in nativen http://javatechig.com/wp-content/uploads/2014/05/Displaying-Progress-Notification-in-Android-Example.png kann Ihnen helfen?Anzeige Fortschrittsbalken in cordova lokale Benachrichtigung

+0

bekam keine Antwort? –

+0

leider nicht – ginfo1

Antwort

0

Verwenden Plugin cordova-File-Transfer- und die folgenden Änderungen:

Sie können das Plugin auf diese Weise für Android-Plattform ändern.

erstellen Klasse FileProgressBarTask mit Balg 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()); 
    } 
} 

ändern Klasse FileTransfer mit Balg 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; 

Auf der Linie ~ 700 in Methode zum Download auf Klasse FileTransfer:

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

Suchen Sie den Blockcode für die Methode d ownload das enthält: while und progress.setLoaded(inputStream.getTotalRawBytesRead()); auf Methode herunterladen, legen unten Code:

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

Basierend auf:

Verwandte Themen