将数据上传到服务器并在Android通知栏中显示进度

时间:2012-09-07 06:41:03

标签: android

我已经尝试了很多,但在上传时显示通知的进度却没有成功。我可以使用Asynch Task将数据上传到服务器,但现在我需要将数据上传到服务器并显示在通知栏中,就像我们在Facebook上传图像或视频一样。

我无法做到这一点。我通过asynch上传数据的代码如下。

我在doInBackGround()方法中编写下面的代码:

            HttpClient httpClient = new DefaultHttpClient();
            HttpPost postRequest = new HttpPost(
                    "http://********.php?f=setAvatar");
            ByteArrayBody bab = new ByteArrayBody(data, "receipt.jpg");
            // File file= new File("/mnt/sdcard/forest.png");
            // FileBody bin = new FileBody(file);
            File file = new File(ProfileEdit.selectedImagePath);
            MultipartEntity reqEntity = new MultipartEntity(
                    HttpMultipartMode.BROWSER_COMPATIBLE);
            ContentBody cbFile = new FileBody(file, "image/jpeg");
            reqEntity.addPart("im", cbFile);
            reqEntity.addPart("u", new StringBody(USERID));
            reqEntity.addPart("k", new StringBody(KEY));
            reqEntity.addPart("p", new StringBody(pannelId));

            //reqEntity.addPart("id", new StringBody(password));
            //reqEntity.addPart("addExpenseResult", new StringBody(expenceresult));
            postRequest.setEntity(reqEntity);
            HttpResponse response = httpClient.execute(postRequest);
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    response.getEntity().getContent(), "UTF-8"));
            String sResponse;
            StringBuilder s = new StringBuilder();

1 个答案:

答案 0 :(得分:0)