我需要知道有多少个字节已经上传了更新进度条的android [英] I need know how much bytes has been uploaded for update a progress bar android

查看:153
本文介绍了我需要知道有多少个字节已经上传了更新进度条的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发用于上传视频到的Apache / PHP服务器一个应用程序。在这一刻,我已经可以上传视频。我需要显示一个进度条,而该文件被上传。我使用的AsyncTask和HTTP 4.1.1库用于模拟形成下一个code。

I am developing an app for upload video to a Apache/PHP Server. In this moment I already can upload videos. I need show a progress bar while the file is being uploaded. I have the next code using AsyncTask and HTTP 4.1.1 Libraries for emulate the FORM.

class uploadVideo extends AsyncTask<Void,Void,String>{

    @Override
    protected String doInBackground(Void... params) {
        // Create a new HttpClient and Post Header
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://www.youtouch.cl/videoloader/index.php");           
        try {
            // Add your data
            File input=new File(fileName);              

            MultipartEntity multi=new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);                

            multi.addPart("video", new FileBody(input));                

            httppost.setEntity(multi);

            // Execute HTTP Post Request
            HttpResponse response = httpclient.execute(httppost);               

            HttpEntity entity = response.getEntity();

            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(
                            entity.getContent(), "UTF-8"));
            String sResponse = reader.readLine();
            return sResponse;

        } catch (ClientProtocolException e) {
            Log.v("Uri Galeria", e.toString());
            e.printStackTrace();                

        } catch (IOException e) {
            Log.v("Uri Galeria", e.toString());
            e.printStackTrace();                
        }
        return "error";
    }

    @Override
    protected void onProgressUpdate(Void... unsued) {
                //Here I do should update the progress bar
    }

    @Override
    protected void onPostExecute(String sResponse) {
        try {
            if (pd.isShowing())
                pd.dismiss();

            if (sResponse != null) {
                JSONObject JResponse = new JSONObject(sResponse);
                int success = JResponse.getInt("SUCCESS");
                String message = JResponse.getString("MESSAGE");
                if (success == 0) {
                    Toast.makeText(getApplicationContext(), message,
                            Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(getApplicationContext(),
                            "Video uploaded successfully",
                            Toast.LENGTH_SHORT).show();

                }
            }
        } catch (Exception e) {
            Toast.makeText(getApplicationContext(),
                    e.getMessage(),
                    Toast.LENGTH_LONG).show();
            Log.e(e.getClass().getName(), e.getMessage(), e);
        }
    }

我需要知道在哪里可以得到多少字节已上载。 File.length是总大小。

I need know where I can get how much bytes has been uploaded. File.length is the total size.

PD:对不起,我的英语是有规律的。

PD: Sorry, my english is regular

推荐答案

检查我的答案在这里,我想这回答了你的问题: 但更新到您要上传的视频图像的文件路径

Check my answer here, I guess it answers your question: But update the file path of the image to your to be uploaded video

<一个href="http://stackoverflow.com/a/19295719/463846">http://stackoverflow.com/questions/15572747/progressbar-in-asynctask-is-not-showing-on-upload

这篇关于我需要知道有多少个字节已经上传了更新进度条的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆