[英]Progress bar in notification bar while uploading image to a server in Android
[英]Uploading data to server and displaying progress in Android notification bar
我已經嘗試了很多,但是在上傳通知中顯示進度沒有成功。 我可以使用Asynch Task將數據上傳到服務器,但是現在我需要將數據上傳到服務器並顯示在通知欄中,就像我們在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();
您可以使用RemoteView
和PendingIntent
在通知欄上顯示,請參考: http : //developer.android.com/guide/topics/ui/notifiers/notifications.html#CustomExpandedView
有關詳細進度, 我需要知道已上傳了多少字節以更新進度條android
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.