Is there any way to get upload progress correctly with HttpUrlConncetion

后端 未结 2 721
滥情空心
滥情空心 2021-02-14 05:52

Android Developers Blog recommend to use HttpURLConnection other than apache\'s HttpClient (http://android-developers.blogspot.com/2011/09/androids-htt

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-14 06:14

    use Asynctask to upload file to upload your file to server and create a Progressdialog

    1) run your code in

     doinbackground(){
        your code here..
    }
    

    2) update the progress in

    publishProgress("" + (int) ((total * 100) / lenghtOfFile));
        //type this in the while loop before write..
    

    3) and On updating the progress

    protected void onProgressUpdate(String... progress) {
                Progress.setProgress(Integer.parseInt(progress[0]));
            }
    

    4) dismiss the progress in

    protected void onPostExecute(String file_url) {
                dismissDialog(progress);
    

提交回复
热议问题