如何实现挂起上传到android服务器
我正在开发一个应用程序,使用nojs作为服务器,它的主要功能是上传图像,视频和笔记到服务器 我想关心的情况是,当用户有限制bandwith或没有互联网连接,所以我希望我的应用程序中的所有文件都更改为挂起状态,等待用户恢复互联网连接 这是我在AsyncTask类上载中的代码如何实现挂起上传到android服务器,android,file-upload,Android,File Upload,我正在开发一个应用程序,使用nojs作为服务器,它的主要功能是上传图像,视频和笔记到服务器 我想关心的情况是,当用户有限制bandwith或没有互联网连接,所以我希望我的应用程序中的所有文件都更改为挂起状态,等待用户恢复互联网连接 这是我在AsyncTask类上载中的代码 File file = new File(imgPath); //Create the POST object HttpPost post = new HttpPost(url
File file = new File(imgPath);
//Create the POST object
HttpPost post = new HttpPost(url);
MultipartEntity entity = new MyMultipartEntity(new ProgressListener()
{
@Override
public void transferred(long num)
{
//Call the onProgressUpdate method with the percent completed
publishProgress((int) ((num / (float) totalSize) * 100));
Log.d("DEBUG", num + " - " + totalSize);
}
});
//Add the file to the content's body
ContentBody cbFile = new FileBody( file, "video/mp4" );
entity.addPart("source", cbFile);
//After adding everything we get the content's lenght
totalSize = entity.getContentLength();
//We add the entity to the post request
post.setEntity(entity);
//Execute post request
HttpResponse response = client.execute( post );
int statusCode = response.getStatusLine().getStatusCode();
if(statusCode == HttpStatus.SC_OK){
//If everything goes ok, we can get the response
String fullRes = EntityUtils.toString(response.getEntity());
Log.d("DEBUG", fullRes);
} else {
Log.d("DEBUG", "HTTP Fail, Response Code: " + statusCode);
}
有没有办法解决这个问题?您需要实现一个广播接收器,当设备上的连接发生变化时会调用该接收器 当您收到消息时,您可以检查任何挂起的上载并继续(您需要实现此逻辑) 您的广播接收器需要处理android.net.conn.CONNECTIVITY\u更改。如何做到这一点是很好的文件在这里,所以或一个好的地方开始