本文整理汇总了Java中android.app.DownloadManager.Request类的典型用法代码示例。如果您正苦于以下问题:Java Request类的具体用法?Java Request怎么用?Java Request使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Request类属于android.app.DownloadManager包,在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: downloadIssue
import android.app.DownloadManager.Request; //导入依赖的package包/类
public void downloadIssue() {
if(!this.canDisplayPdf(getActivity())) {
Toast.makeText(getActivity(), getActivity().getString(R.string.pdf_reader_required), Toast.LENGTH_LONG).show();
return;
}
String file = issue.getId() + ".pdf";
File magPiFolder = new File (Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + Config.ISSUE_FOLDER);
magPiFolder.mkdirs();
File pdf = new File (Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + Config.ISSUE_FOLDER, file);
if(pdf.exists() && !isDownloading(issue.getPdfUrl())) {
Intent intentPdf = new Intent(Intent.ACTION_VIEW);
intentPdf.setDataAndType(Uri.fromFile(pdf), "application/pdf");
startActivity(intentPdf);
} else if (!isDownloading(issue.getPdfUrl())) {
menu.findItem(R.id.menu_view).setVisible(false);
menu.findItem(R.id.menu_cancel_download).setVisible(true);
Request request = new Request(Uri.parse(issue.getPdfUrl()));
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
request.setTitle(getActivity().getString(R.string.app_name) + " n�" + issue.getId());
request.setDescription(getActivity().getString(R.string.download_text) + " n�" + issue.getId());
request.setDestinationInExternalPublicDir(Config.ISSUE_FOLDER, file);
dm.enqueue(request);
}
}
示例2: updateClientsWithMetadataUri
import android.app.DownloadManager.Request; //导入依赖的package包/类
/**
* Download latest metadata from the server through DownloadManager for all relevant clients
*
* @param context The context for retrieving resources
* @param metadataUri The client to update
*/
private static void updateClientsWithMetadataUri(
final Context context, final String metadataUri) {
Log.i(TAG, "updateClientsWithMetadataUri() : MetadataUri = " + metadataUri);
// Adding a disambiguator to circumvent a bug in older versions of DownloadManager.
// DownloadManager also stupidly cuts the extension to replace with its own that it
// gets from the content-type. We need to circumvent this.
final String disambiguator = "#" + System.currentTimeMillis()
+ ApplicationUtils.getVersionName(context) + ".json";
final Request metadataRequest = new Request(Uri.parse(metadataUri + disambiguator));
DebugLogUtils.l("Request =", metadataRequest);
final Resources res = context.getResources();
metadataRequest.setAllowedNetworkTypes(Request.NETWORK_WIFI | Request.NETWORK_MOBILE);
metadataRequest.setTitle(res.getString(R.string.download_description));
// Do not show the notification when downloading the metadata.
metadataRequest.setNotificationVisibility(Request.VISIBILITY_HIDDEN);
metadataRequest.setVisibleInDownloadsUi(
res.getBoolean(R.bool.metadata_downloads_visible_in_download_UI));
final DownloadManagerWrapper manager = new DownloadManagerWrapper(context);
if (maybeCancelUpdateAndReturnIfStillRunning(context, metadataUri, manager,
DictionaryService.NO_CANCEL_DOWNLOAD_PERIOD_MILLIS)) {
// We already have a recent download in progress. Don't register a new download.
return;
}
final long downloadId;
synchronized (sSharedIdProtector) {
downloadId = manager.enqueue(metadataRequest);
DebugLogUtils.l("Metadata download requested with id", downloadId);
// If there is still a download in progress, it's been there for a while and
// there is probably something wrong with download manager. It's best to just
// overwrite the id and request it again. If the old one happens to finish
// anyway, we don't know about its ID any more, so the downloadFinished
// method will ignore it.
writeMetadataDownloadId(context, metadataUri, downloadId);
}
Log.i(TAG, "updateClientsWithMetadataUri() : DownloadId = " + downloadId);
}
示例3: downloadUri
import android.app.DownloadManager.Request; //导入依赖的package包/类
@SuppressWarnings("ResultOfMethodCallIgnored")
public static void downloadUri(
Context context, Uri uri, String fileName, @Nullable String mimeType) {
// Create the destination location
File destination = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS);
destination.mkdirs();
Uri destinationUri = Uri.fromFile(new File(destination, fileName));
// Use the download manager to perform the download
DownloadManager downloadManager =
(DownloadManager) context.getSystemService(Activity.DOWNLOAD_SERVICE);
Request request = new Request(uri)
.setNotificationVisibility(Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
.setDestinationUri(destinationUri);
if (mimeType != null) {
request.setMimeType(mimeType);
}
request.allowScanningByMediaScanner();
downloadManager.enqueue(request);
}
示例4: download
import android.app.DownloadManager.Request; //导入依赖的package包/类
public void download(DownloadTask task) {
//TODO better path
DownloadManager downloadManager = (DownloadManager) UpodsApplication.getContext().getSystemService(Context.DOWNLOAD_SERVICE);
Uri episodUri = Uri.parse(task.track.getAudeoUrl());
String trackName = GlobalUtils.getCleanFileName(task.track.getTitle()) + ".mp3";
String mediaItemName = GlobalUtils.getCleanFileName(task.mediaItem.getName());
String finalPath = PODCASTS_DOWNLOAD_DIRECTORY + "/" + mediaItemName + "/" + trackName;
finalPath = Environment.getExternalStorageDirectory() + finalPath;
Request request = new Request(episodUri);
request.setAllowedNetworkTypes(Request.NETWORK_MOBILE | Request.NETWORK_WIFI);
request.setTitle(task.track.getTitle());
request.setDescription(task.track.getSubTitle());
request.setDestinationUri(Uri.fromFile(new File(finalPath)));
task.downloadId = downloadManager.enqueue(request);
task.filePath = finalPath;
allTasks.add(task);
Logger.printInfo(DM_LOG, "Starting download episod " + trackName + " to " + finalPath);
runProgressUpdater();
}
示例5: getDownloadListener
import android.app.DownloadManager.Request; //导入依赖的package包/类
private DownloadListener getDownloadListener() {
return new DownloadListener() {
public void onDownloadStart(
String url,
String userAgent,
String contentDisposition,
String mimetype,
long contentLength
) {
Uri uri = Uri.parse(url);
Request request = new Request(uri);
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setTitle("File download from Mattermost");
String cookie = CookieManager.getInstance().getCookie(url);
if (cookie != null) {
request.addRequestHeader("cookie", cookie);
}
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
}
};
}
示例6: download
import android.app.DownloadManager.Request; //导入依赖的package包/类
/**
* 下载目标地址数据至SD卡默认目录
*
* @param context 当前环境
* @param url 地址
* @return 下载编号
*/
public static final long download(Context context, String url,
String fileName) {
DownloadManager downloadManager = getDownloadManager(context);
if (downloadManager != null) {
Uri uri = Uri.parse(url);
File file = new File(Environment.getExternalStorageDirectory()
.getPath() + File.separator + fileName);
/*
* 判断文件是否存在,如果存在删除源文件
*/
if (file.exists()) {
file.delete();
}
Request request = new Request(uri);
request.setTitle("正在下载……");
request.setDestinationUri(Uri.parse(Uri.fromFile(
Environment.getExternalStorageDirectory()).toString()
+ File.separator + fileName)); // 设置下载后文件存放的位置
Toast.makeText(context, "开始下载更新包,请稍后……", Toast.LENGTH_LONG).show();
return downloadManager.enqueue(request);
}
return 0;
}
示例7: download
import android.app.DownloadManager.Request; //导入依赖的package包/类
@Override
public void download(Context context, Uri uri, String filename) {
DownloadManager.Request r = null;
try {
r = new DownloadManager.Request(uri);
} catch (IllegalArgumentException e) {
/* Unmodified Android 2.3 doesn't allow downloads over HTTPS - check if
* this is an exception related to this */
if(e.getMessage() != null && e.getMessage().contains("HTTP URIs")) {
Toast.makeText(context, R.string.error_download_not_supported_https, Toast.LENGTH_SHORT).show();
return;
} else {
// rethrow exception if it's not about HTTPS downloads
throw e;
}
}
setupRequest(r, uri, filename);
// Start download
DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
dm.enqueue(r);
}
示例8: enqueue
import android.app.DownloadManager.Request; //导入依赖的package包/类
public long enqueue(String uri, String name, int epi, String vid){
Request request = new Request(Uri.parse(uri));
request.setAllowedNetworkTypes(Request.NETWORK_WIFI);
String externd = uri.substring(uri.lastIndexOf('.'));
String file = name;
String dir = "NetVideo" ;
if(epi != 0){
file += epi;
dir = dir + "/" + name;
}
request.setTitle(file);
request.setDestinationInExternalPublicDir(dir, file + "." + externd);
request.setMimeType("media/video");
request.setDescription(vid);
return mDownloadManager.enqueue(request);
}
示例9: do_download
import android.app.DownloadManager.Request; //导入依赖的package包/类
private void do_download() {
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
for(WikiDBFile wdbf : wiki.getDBFiles()) {
Request request = new Request(
Uri.parse(wdbf.getUrl()));
String destinationPath = new File(
new File(storage,getString(R.string.DBDir)),
wdbf.getFilename()).getAbsolutePath();
request.setDestinationUri(Uri.parse("file://"+destinationPath));
request.setTitle(wdbf.getFilename());
dm.enqueue(request);
}
downloadbutton.setVisibility(View.GONE);
stopdownloadbutton.setVisibility(View.VISIBLE);
}
示例10: listing603
import android.app.DownloadManager.Request; //导入依赖的package包/类
private void listing603()
{
/**
* Listing 6-3: Downloading files using the Download Manager
*/
String serviceString = Context.DOWNLOAD_SERVICE;
DownloadManager downloadManager = ( DownloadManager ) getSystemService( serviceString );
Uri uri = Uri.parse( getString( R.string.my_feed2 ) );
DownloadManager.Request request = new Request( uri );
long reference = downloadManager.enqueue( request );
//
myDownloadReference = reference;
Log.d( TAG, "Download Reference: " + reference );
}
示例11: createDownloadRequest
import android.app.DownloadManager.Request; //导入依赖的package包/类
private Request createDownloadRequest(String url, String fileName,
String downloadTitle) {
Request request = new Request(Uri.parse(url));
Environment.getExternalStoragePublicDirectory(
Environment.getExternalStorageDirectory()
+ VersionParserHelper.UPDATER_FOLDER).mkdirs();
request.setDestinationInExternalPublicDir(
VersionParserHelper.UPDATER_FOLDER, fileName);
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
request.setAllowedOverRoaming(false);
request.setTitle(downloadTitle);
return request;
}
示例12: createDownloadRequest
import android.app.DownloadManager.Request; //导入依赖的package包/类
private Request createDownloadRequest(String url, String fileName) {
Request request = new Request(Uri.parse(url));
Environment.getExternalStoragePublicDirectory(
Environment.getExternalStorageDirectory()
+ VersionParserHelper.UPDATER_FOLDER).mkdirs();
request.setDestinationInExternalPublicDir(
VersionParserHelper.UPDATER_FOLDER, fileName);
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
request.setAllowedOverRoaming(false);
Resources resources = getApplicationContext().getResources();
request.setTitle(resources.getString(R.string.downloadUpdateTitle));
return request;
}
示例13: createDownloadRequest
import android.app.DownloadManager.Request; //导入依赖的package包/类
private Request createDownloadRequest(String url, String fileName) {
Request request = new Request(Uri.parse(url));
Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS).mkdirs();
request.setDestinationInExternalPublicDir(
Environment.DIRECTORY_DOWNLOADS, fileName);
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
request.setAllowedOverRoaming(false);
String download = mContext.getResources().getString(
R.string.google_apps_download_title);
request.setTitle(download);
return request;
}
示例14: createDownloadRequest
import android.app.DownloadManager.Request; //导入依赖的package包/类
private Request createDownloadRequest(String url, String fileName) {
Request request = new Request(Uri.parse(url));
Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS).mkdirs();
request.setDestinationInExternalPublicDir(
Environment.DIRECTORY_DOWNLOADS, fileName);
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI );
request.setAllowedOverRoaming(false);
String download = mContext.getResources().getString(
R.string.google_apps_download_title);
request.setTitle(download);
return request;
}
示例15: tempDownloadToSdcard
import android.app.DownloadManager.Request; //导入依赖的package包/类
private void tempDownloadToSdcard(Request request) {
videoUri = Uri.parse(dir_Downloads.toURI() + composedVideoFilename);
Utils.logger("d", "** NEW ** videoUri: " + videoUri, DEBUG_TAG);
request.setDestinationUri(videoUri);
try {
enqueue = dm.enqueue(request);
} catch (IllegalArgumentException e) {
Log.e(DEBUG_TAG, "tempDownloadToSdcard: " + e.getMessage());
BugSenseHandler.sendExceptionMessage(DEBUG_TAG + "-> tempDownloadToSdcard", e.getMessage(), e);
} catch (NullPointerException ne) {
Log.e(DEBUG_TAG, "callDownloadApk: " + ne.getMessage());
BugSenseHandler.sendExceptionMessage(DEBUG_TAG + "-> tempDownloadToSdcard: ", ne.getMessage(), ne);
Toast.makeText(this, getString(R.string.error), Toast.LENGTH_LONG).show();
}catch (SecurityException se) {
Log.e(DEBUG_TAG, "callDownloadApk: " + se.getMessage());
BugSenseHandler.sendExceptionMessage(DEBUG_TAG + "-> tempDownloadToSdcard: ", se.getMessage(), se);
Toast.makeText(this, getString(R.string.error), Toast.LENGTH_LONG).show();
}
}