【问题标题】:Uploading data to server and displaying progress in Android notification bar将数据上传到服务器并在 Android 通知栏中显示进度
【发布时间】:2019-03-30 07:47:35
【问题描述】:

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

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

我在 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();

【问题讨论】:

    标签: android


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 2016-01-14
    • 1970-01-01
    • 2021-10-10
    • 1970-01-01
    • 2018-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多