2011-08-22 59 views
0

IntentService我打開Notification顯示ProgressBar
的問題是,如果我不跌10點。
正在調用進度10次10​​%,20%,30 ...如何計算ProgressBar的下載進度

這種行爲預期的呼叫通知區域將凍結?
我想知道更好的做法。

我現在做的是一些奇特初學者的計算是這樣的:

long filesize = bis.available(); 
double Mbyte = (double)filesize/ (1024*1024); 
filesize = (filesize - resumeLong); 

totalMbSent = totalMbSent + (double)filesize; 
DecimalFormat dec = new DecimalFormat("0.00"); 
String result = dec.format(Mbyte); 

int c10 = 0;int c20 = 0;int c30 = 0;int c40 = 0;int c50 = 0;int c60 = 0;int c70 = 0;int c80 = 0;int c90 = 0; 
int proc = (int) (filesize/10); 
int proc10 = proc; // 10% 
int proc20 = proc+proc; // 20& 
int proc30 = proc+proc+proc; //30% 
int proc40 = proc+proc+proc+proc; 
int proc50 = proc+proc+proc+proc+proc; 
int proc60 = proc+proc+proc+proc+proc+proc; 
int proc70 = proc+proc+proc+proc+proc+proc+proc; 
int proc80 = proc+proc+proc+proc+proc+proc+proc+proc; 
int proc90 = proc+proc+proc+proc+proc+proc+proc+proc+proc; 
while ((val = bis.read(buffer, 0, 1024)) > 0) { 
    out.write(buffer, 0, val); 
    filesize -= val; 
    if (filesize < 1024) { 
     val = (int) filesize; 
    } 

    // This is for the notification showing progress in percent 
    if (c10 == 0 && filesize > proc10 && filesize < proc20){ 
     c10 = 1 ;setNotificationProgress(sendingFile+" " + count + 
     "/" + max + " " + result + "Mb", Notification.FLAG_NO_CLEAR,90,false); 
    }else if(c20 == 0 && filesize > proc20 && filesize < proc30){ 
     c20 = 1 ;setNotificationProgress(sendingFile+" " + count + 
     "/" + max + " " + result + "Mb" , Notification.FLAG_NO_CLEAR,80,false); 
    }else if(c30 == 0 && filesize > proc30 && filesize < proc40){ 
     c30 = 1 ;setNotificationProgress(sendingFile+" " + count + 
     "/" + max + " " + result + "Mb" , Notification.FLAG_NO_CLEAR,70,false); 
    }else if(c40 == 0 && filesize > proc40 && filesize < proc50){ 
     c40 = 1 ;setNotificationProgress(sendingFile+" " + count + 
     "/" + max + " " + result + "Mb" , Notification.FLAG_NO_CLEAR,60,false); 
    }else if(c50 == 0 && filesize > proc50 && filesize < proc60){ 
     c50 = 1 ;setNotificationProgress(sendingFile+" " + count + 
     "/" + max + " " + result + "Mb" , Notification.FLAG_NO_CLEAR,50,false); 
    }else if(c60 == 0 && filesize > proc60 && filesize < proc70){ 
     c60 = 1 ;setNotificationProgress(sendingFile+" " + count + 
     "/" + max + " " + result + "Mb" , Notification.FLAG_NO_CLEAR,40,false); 
    }else if(c70 == 0 && filesize > proc70 && filesize < proc80){ 
     c70 = 1 ;setNotificationProgress(sendingFile+" " + count + 
     "/" + max + " " + result + "Mb" , Notification.FLAG_NO_CLEAR,30,false); 
    }else if(c80 == 0 && filesize > proc80 && filesize < proc90){ 
     c80 = 1 ;setNotificationProgress(sendingFile+" " + count + 
     "/" + max + " " + result + "Mb" , Notification.FLAG_NO_CLEAR,20,false); 
    }else if(c90 == 0 && filesize > proc90 && filesize < filesize){ 
     c90 = 1 ;setNotificationProgress(sendingFile+" " + count + 
     "/" + max + " " + result + "Mb" , Notification.FLAG_NO_CLEAR,10,false); 
    } 
} 
+0

這是一個艱難的:) – Erik

回答

0

的解決方案是簡單地編寫代碼的方式,它不
超載通知引擎。