The solution I use in these cases is:
1 - Use loopj library to send a file via POST to my server (php p.ex)
// loopj supports Http Auth, cookies, params, multipart files, etc. So is a good solution. Like: ... AsyncHttpClient client = new AsyncHttpClient(); client.addHeader("Authorization", "Basic " + Base64.encodeToString("aaa:bbb".getBytes(), Base64.NO_WRAP)); RequestParams params = new RequestParams(); params.put("cmd", "upp"); params.put("uid", Long.toString(getUser().getId())); params.put("tid", Long.toString(getUser().getIdTeam())); try{ params.put("avatar", file); // File object }catch(FileNotFoundException e){ ... } SharePhotoHandler handler=new SharePhotoHandler(mContext,file,notificate); client.post(URI_BASE, params, handler); ...
And I use a custom handler to control file upload (SharePhotoHandler.class), where the application can control
- Onsuccess
- Onfailure
- onfinish
- ...
These methods should allow you to monitor the status of the fileโs upload / download (ok, error, upload, download, etc.).
After downloading the file, the server should notify other clients that there is a new file to download, or, using your onSuccess method, send a GCM message to other clients. In my case, the server sends the file name (+ URL) to other clients to download it.
source share