本文整理汇总了Java中com.lidroid.xutils.HttpUtils.download方法的典型用法代码示例。如果您正苦于以下问题:Java HttpUtils.download方法的具体用法?Java HttpUtils.download怎么用?Java HttpUtils.download使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.lidroid.xutils.HttpUtils
的用法示例。
在下文中一共展示了HttpUtils.download方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: download
import com.lidroid.xutils.HttpUtils; //导入方法依赖的package包/类
public static void download(String url, String path,
final IOAuthCallBack iOAuthCallBack) {
HttpUtils http = new HttpUtils();
HttpHandler<File> handler = http.download(url, path, false, // 如果目标文件存在,接着未完成的部分继续下载。服务器不支持RANGE时将从新下载。
false, // 如果从请求返回信息中获取到文件名,下载完成后自动重命名。
new RequestCallBack<File>() {
@Override
public void onSuccess(ResponseInfo<File> arg0) {
if (d)
Log.d("-----downfile-----", "success");
iOAuthCallBack.getIOAuthCallBack(arg0.result.getName(),
0);
}
@Override
public void onFailure(com.lidroid.xutils.exception.HttpException e, String s) {
if (d)
Log.d("-----downfile-----", "fail");
iOAuthCallBack.getIOAuthCallBack(e.toString(), 1);
}
});
}
示例2: downAPK
import com.lidroid.xutils.HttpUtils; //导入方法依赖的package包/类
/**
* 下载APK的方法
* @param url 要下载文件的路径
* @param targetFile 下载文件的本地路径
* @param myCallBack 一个接口对象用于监听文件下载的状态
*/
public void downAPK(String url, String targetFile, final MyCallBack myCallBack) {
//创建HttpUtils对象
HttpUtils httpUtils = new HttpUtils();
//调用HttpUtils的下载方法下载指定文件
httpUtils.download(url, targetFile, new RequestCallBack<File>() {
@Override
public void onSuccess(ResponseInfo<File> responseInfo) {
myCallBack.onSuccess(responseInfo);
}
@Override
public void onFailure(HttpException e, String s) {
myCallBack.onFailure(e,s);
}
@Override
public void onLoading(long total, long current, boolean isUploading) {
super.onLoading(total, current, isUploading);
myCallBack.onLoading(total,current,isUploading);
}
});
}
示例3: addNewDownload
import com.lidroid.xutils.HttpUtils; //导入方法依赖的package包/类
public void addNewDownload(String url, String fileName, String target,
boolean autoResume, boolean autoRename,
final RequestCallBack<File> callback) throws DbException {
final DownloadInfo downloadInfo = new DownloadInfo();
downloadInfo.setDownloadUrl(url);
downloadInfo.setAutoRename(autoRename);
downloadInfo.setAutoResume(autoResume);
downloadInfo.setFileName(fileName);
downloadInfo.setFileSavePath(target);
HttpUtils http = new HttpUtils();
http.configRequestThreadPoolSize(maxDownloadThread);
HttpHandler<File> handler = http.download(url, target, autoResume, autoRename, new ManagerCallBack(downloadInfo, callback));
downloadInfo.setHandler(handler);
downloadInfo.setState(handler.getState());
downloadInfoList.add(downloadInfo);
db.saveBindingId(downloadInfo);
}
示例4: saveShareFile
import com.lidroid.xutils.HttpUtils; //导入方法依赖的package包/类
public void saveShareFile(String url, SaveFileListener listener) {
File files = new File(url);
if(files.exists()){
String savePath = ConstantsPath.getDCIMPath();
FileUtils_zm.getInst().copyFile(files.toString(), savePath);
listener.onSuccess(savePath);
return;
}
String[] resultArr = url.split("/");
String baseName = resultArr[resultArr.length - 1];
String savepath = ConstantsPath.getCachePath() + "/" + String.valueOf(baseName.hashCode());
HttpUtils http = new HttpUtils();
File file = new File(savepath);
if (file.exists()) {
listener.onSuccess(savepath);
return;
}
http.download(Constants.setAliyunImageUrl(url), savepath, true, true,
new RequestCallBack<File>() {
@Override
public void onSuccess(ResponseInfo<File> responseInfo) {
listener.onSuccess(savepath);
}
@Override
public void onFailure(HttpException e, String s) {
Log.e("saveShareFile", "failed" + e.getMessage() + " -- message: " + s);
}
});
}
示例5: loadSmileyZip
import com.lidroid.xutils.HttpUtils; //导入方法依赖的package包/类
private static void loadSmileyZip(final Context context, String url) {
// ZogUtils.printError(LoadEmojiUtils.class, "loadSmileyZip url:" + url);
initDir(context);
HttpUtils http = new HttpUtils();
http.download(url, SmileyUtils.getSmileyZipFilePath(context),
true,// 如果目标文件存在,接着未完成的部分继续下载。服务器不支持RANGE时将重新下载。
false, // 如果从请求返回信息中获取到文件名,下载完成后自动重命名。
new RequestCallBack<File>() {
@Override
public void onStart() {
super.onStart();
ZogUtils.printError(LoadEmojiUtils.class, "loadSmileyZip onStart");
}
@Override
public void onSuccess(ResponseInfo<File> responseInfo) {
ZogUtils.printError(LoadEmojiUtils.class, "loadSmileyZip onSuccess dir:" + responseInfo.result.getPath());
SmileyInfo smileyInfo = AppSPUtils.getContentConfig(context).getSmileyInfo();
String fileMD5 = MD5Utils.getFileMD5(new File(SmileyUtils.getSmileyZipFilePath(context)));
ZogUtils.printError(LoadEmojiUtils.class, "fileMD5:" + fileMD5 + " smileyInfo.getMD5()):" + smileyInfo.getMD5());
// if (fileMD5.equals(smileyInfo.getMD5())) {
loadSmileyMap(context);
// } else {
// ZogUtils.printError(LoadEmojiUtils.class, "Smiley Zip MD5不匹配");
// }
}
@Override
public void onFailure(HttpException e, String s) {
ZogUtils.printError(LoadEmojiUtils.class, "loadSmileyZip onFailure");
SmileyUtils.distory(context);
// JsonUtils.printAsJson(e);
// ToastUtils.mkLongTimeToast(context, context.getString(R.string.download_emoji_fail));
}
});
}
示例6: onHandleIntent
import com.lidroid.xutils.HttpUtils; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
String url = intent.getStringExtra(URL);
String path = intent.getStringExtra(PATH_);
String fileName = intent.getStringExtra(FILE_NAME);
boolean lrc = intent.getBooleanExtra(IS_LRC_DOWN , false);
if (lrc){
HttpUtils httpUtils = new HttpUtils();
if (url != null){
httpUtils.download(url, path + fileName + ".lrc", true, true, new RequestCallBack<File>() {
@Override
public void onSuccess(ResponseInfo<File> responseInfo) {
Log.d("test" ,"downloaded" );
EventBus.getDefault().post(responseInfo.result);
}
@Override
public void onFailure(HttpException e, String s) {
Log.d("test" , "下载失败 " + s);
}
});
}
}else{
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setDestinationInExternalPublicDir(path , fileName);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);
request.setVisibleInDownloadsUi(true);
DownloadManager downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
downloadManager.enqueue(request);
}
}
示例7: resumeDownload
import com.lidroid.xutils.HttpUtils; //导入方法依赖的package包/类
/**
* 恢复下载
*
* @param BookDownloadInfo
* @param callback
* @throws DbException
*/
public void resumeDownload(BookDownloadInfo BookDownloadInfo,
final RequestCallBack<File> callback) throws DbException {
HttpUtils http = new HttpUtils();
http.configRequestThreadPoolSize(maxDownloadThread);
HttpHandler<File> handler = http.download(BookDownloadInfo
.getDownloadUrl(), BookDownloadInfo.getFileSavePath(),
BookDownloadInfo.isAutoResume(), BookDownloadInfo
.isAutoRename(), new ManagerCallBack(BookDownloadInfo,
callback));
BookDownloadInfo.setHandler(handler);
BookDownloadInfo.setState(handler.getState());
db.saveOrUpdate(BookDownloadInfo);
}
示例8: resumeDownload
import com.lidroid.xutils.HttpUtils; //导入方法依赖的package包/类
public void resumeDownload(DownloadInfo downloadInfo, final RequestCallBack<File> callback) throws DbException {
HttpUtils http = new HttpUtils();
http.configRequestThreadPoolSize(maxDownloadThread);
HttpHandler<File> handler = http.download(
downloadInfo.getDownloadUrl(),
downloadInfo.getFileSavePath(),
downloadInfo.isAutoResume(),
downloadInfo.isAutoRename(),
new ManagerCallBack(downloadInfo, callback));
downloadInfo.setHandler(handler);
downloadInfo.setState(handler.getState());
db.saveOrUpdate(downloadInfo);
}
示例9: downloadApk
import com.lidroid.xutils.HttpUtils; //导入方法依赖的package包/类
protected void downloadApk() {
File downloadPath = getExternalCacheDir();
File down = Environment.getDownloadCacheDirectory();
Log.e(TAG, "downloadPath :" + downloadPath.getAbsolutePath());
HttpUtils http = new HttpUtils();
Log.e(TAG, "apkurl :" + apkurl);
String targetPath = getExternalCacheDir()
+ apkurl.substring(apkurl.lastIndexOf("/"));
HttpHandler handler = http.download(apkurl, targetPath, false, false,
new RequestCallBack<File>() {
@Override
public void onStart() {
Toast.makeText(getApplicationContext(), "���ؿ�ʼ",
Toast.LENGTH_LONG).show();
}
@Override
public void onLoading(long total, long current,
boolean isUploading) {
int progress = (int) (current * 100 / total);
Log.e(TAG, progress + "%");
Toast.makeText(getApplicationContext(),
"������" + progress + "%", Toast.LENGTH_SHORT)
.show();
}
@Override
public void onSuccess(ResponseInfo<File> responseInfo) {
File file = responseInfo.result;
installApk(file);
}
@Override
public void onFailure(HttpException error, String msg) {
Toast.makeText(getApplicationContext(), "����ʧ��",
Toast.LENGTH_SHORT).show();
}
});
}
示例10: downFile
import com.lidroid.xutils.HttpUtils; //导入方法依赖的package包/类
public void downFile() {
DeleteFileUtil.delAllFile(fullSaveDir);
HttpUtils http = new HttpUtils();
RequestParams requestParams = new RequestParams();
BaseWebUrl.fillDeviceAndRomInfo(requestParams);
@SuppressWarnings("unused")
HttpHandler<File> handler = http.download(//
downloadUrl, //
fullAppSavePath, //
requestParams, //
true, // 如果目标文件存在,接着未完成的部分继续下载。服务器不支持RANGE时将从新下载。
true, // 如果从请求返回信息中获取到文件名,下载完成后自动重命名。
new RequestCallBack<File>() {
private String getPercent(int progress) {
return getString(R.string.update_downloading) + ", " + progress + "%";
}
@Override
public void onStart() {
builder.setContentText(getPercent(DOWNLOAD_STATUS_BEGIN));// 左侧 小 文本
mNotificationManager.notify(APK_UPDATE_DOWNLOAD_ID, builder.build());
}
@Override
public void onLoading(long total, long current, boolean isUploading) {
int percent = (int) ((float) current / total * 100);
downloadTotal = (int) total;
downloadCurrent = (int) current;
builder.setProgress(downloadTotal, downloadCurrent, false);
builder.setContentText(getPercent(percent));
mNotificationManager.notify(APK_UPDATE_DOWNLOAD_ID, builder.build());
}
@Override
public void onSuccess(ResponseInfo<File> responseInfo) {
builder.setOngoing(false);
builder.setProgress(DOWNLOAD_STATUS_FINISH, DOWNLOAD_STATUS_FINISH, false);
builder.setContentText(getPercent(DOWNLOAD_STATUS_FINISH));
mNotificationManager.notify(APK_UPDATE_DOWNLOAD_ID, builder.build());
fileNameOnly = responseInfo.result.getName();
fullAppSavePath = fullSaveDir + fileNameOnly;
readyToInstall();
}
@Override
public void onFailure(HttpException error, String msg) {
// if (!msg.equals("maybe the file has downloaded completely")) {
// // 之前已经下载完成, 但是 不清楚 xUtils 自己是否有 CRC32校验(存在的, 和 要下载的, 是否一模一样)
// }
downloadFail();
}
}
);
}