如何监控URLConnection.getInputStream()Android中的进步,其中javax.swing.ProgressMonitorInputStream中的()不可用? [英] How do I monitor the progress of URLConnection.getInputStream() in Android where javax.swing.ProgressMonitorInputStream() is unavailable?
问题描述
我上传图片到服务器。
URLConnection connection;
/* set up the connection parameters */
最后,通过文件上传到服务器,
And finally, upload the file to the server via,
connection.getInputStream();
我需要出示水平进度
将显示上传进度。那么,如何找到 URLConnection.getInputStream()的进展情况;
I need to show a horizontal ProgressBar
that will display the upload progress. So how do I find the progress of URLConnection.getInputStream();
推荐答案
尝试包装你的上传过程到AsyncTask的。所以,你必须在 doInBackground)
,载(在这里您可以上传您的图片的部分(实际上,具有一定的缓冲液),并经过每一部分都调用下载 publishProgress()
。在 onProgressUpdate()
方法你有新的进展状态更新你的用户界面的能力。您可以更新进度条,或百分之新值设置为TextView的 - 你想要做什么
Try to wrap your uploading process into AsyncTask. So, you'll have uploading in doInBackground()
, where you can upload your image "by parts" (actually, with some buffer), and after each portion is downloaded call publishProgress()
. In onProgressUpdate()
method you have ability to update your ui with the new progress state. You can update your progress bar, or set new percent value to TextView - do what you want.
这篇关于如何监控URLConnection.getInputStream()Android中的进步,其中javax.swing.ProgressMonitorInputStream中的()不可用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!