当前位置: 首页>>代码示例>>Java>>正文


Java HttpUtils.download方法代码示例

本文整理汇总了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);
                   }
               });
}
 
开发者ID:Evan-Galvin,项目名称:FreeStreams-TVLauncher,代码行数:24,代码来源:Tools.java

示例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);
        }
    });
}
 
开发者ID:sh2zqp,项目名称:MobilePhoneSafeProtector,代码行数:30,代码来源:DownLoadUtils.java

示例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);
}
 
开发者ID:Frank-Zhu,项目名称:AndroidAppCodeFramework,代码行数:18,代码来源:DownloadManager.java

示例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);
        }
    });

}
 
开发者ID:junchenChow,项目名称:exciting-app,代码行数:36,代码来源:ImageUtils.java

示例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));
                    }
                });
    }
 
开发者ID:BigAppOS,项目名称:BigApp_Discuz_Android,代码行数:41,代码来源:LoadEmojiUtils.java

示例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);
    }
}
 
开发者ID:kiddot,项目名称:MusicPlay,代码行数:32,代码来源:DownLoadService.java

示例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);
}
 
开发者ID:justingboy,项目名称:CouldBooks,代码行数:21,代码来源:BookDownloadManager.java

示例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);
}
 
开发者ID:Frank-Zhu,项目名称:AndroidAppCodeFramework,代码行数:14,代码来源:DownloadManager.java

示例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();
				}
			});

}
 
开发者ID:liufeiit,项目名称:itmarry,代码行数:41,代码来源:SplashActivity.java

示例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();
                }
            }
    );
}
 
开发者ID:imknown,项目名称:IMKBaseFrameworkLibrary,代码行数:63,代码来源:UpdateService.java


注:本文中的com.lidroid.xutils.HttpUtils.download方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。