最近使用AsyncHttpClient来练手做例子,使用AsyncHttpClient来下载文件到SD卡上
public void AsyncHttpFileDown(View view){
String path=pathET.getText().toString().trim();
//下载之后存放的路径 获取SD卡的路径
File file=new File(Environment.getExternalStorageDirectory(),path.substring(path.lastIndexOf("/")+1));
AsyncHttpClient client=new AsyncHttpClient();
client.get(path, new FileAsyncHttpResponseHandler(file) {
@Override
public void onSuccess(int statusCode, Header[] hander, File file) {
if(statusCode==200){
Toast.makeText(getApplicationContext(), "文件下载成功",0).show();
}
}
@Override
public void onFailure(int statusCode, Header[] hander, Throwable throwable, File file) {
Toast.makeText(getApplicationContext(), "文件下载失败",0).show();
throwable.printStackTrace();
}
});
}