本文整理汇总了Java中android.os.Environment.DIRECTORY_DOWNLOADS属性的典型用法代码示例。如果您正苦于以下问题:Java Environment.DIRECTORY_DOWNLOADS属性的具体用法?Java Environment.DIRECTORY_DOWNLOADS怎么用?Java Environment.DIRECTORY_DOWNLOADS使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.os.Environment
的用法示例。
在下文中一共展示了Environment.DIRECTORY_DOWNLOADS属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDestinationDirectory
private static File getDestinationDirectory(Context context, int destination, boolean running)
throws IOException {
switch (destination) {
case Downloads.Impl.DESTINATION_CACHE_PARTITION:
case Downloads.Impl.DESTINATION_CACHE_PARTITION_PURGEABLE:
case Downloads.Impl.DESTINATION_CACHE_PARTITION_NOROAMING:
if (running) {
return context.getFilesDir();
} else {
return context.getCacheDir();
}
case Downloads.Impl.DESTINATION_EXTERNAL:
final File target = new File(
Environment.getExternalStorageDirectory(), Environment.DIRECTORY_DOWNLOADS);
if (!target.isDirectory() && target.mkdirs()) {
throw new IOException("unable to create external downloads directory");
}
return target;
default:
throw new IllegalStateException("unexpected destination: " + destination);
}
}
示例2: startDownload
private void startDownload() {
Snackbar.make(activity.findViewById(R.id.fragment_container), "Downloading started.", Snackbar.LENGTH_SHORT).show();
String path = Environment.getExternalStorageDirectory().toString() + File.separator +
Environment.DIRECTORY_DOWNLOADS + File.separator + "wulkanowy";
File dir = new File(path);
if(!dir.mkdirs()) {
for (String aChildren : dir.list()) {
new File(dir, aChildren).delete();
}
}
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(update.getUrlToDownload().toString()))
.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE)
.setAllowedOverRoaming(false)
.setTitle("Wulkanowy v" + update.getLatestVersionCode())
.setDescription(update.getLatestVersion())
.setVisibleInDownloadsUi(true)
.setMimeType("application/vnd.android.package-archive")
.setDestinationUri(Uri.fromFile(new File(path + File.separator + update.getLatestVersion() + ".apk")));
downloadManager.enqueue(request);
}
示例3: dirChecker
private static void dirChecker(String dir) {
File f = new File(Environment.DIRECTORY_DOWNLOADS + dir);
if(!f.isDirectory()) {
f.mkdirs();
}
}
示例4: getDownloadDir
public static File getDownloadDir() throws NoExternalStorageException {
return new File(getSignalStorageDir(), Environment.DIRECTORY_DOWNLOADS);
}
示例5: onClick
@Override
public void onClick(View v) {
if (v.getId() == R.id.download) {
checkPermiss();
if (isDownloading) {
Toast.makeText(MainActivity.this, "心急吃不了豆腐", Toast.LENGTH_SHORT).show();
return;
}
DownloadManager.Request request = new DownloadManager.Request(Uri.parse("http://download.taobaocdn.com/wireless/taobao4android/latest/701483.apk"));
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);
request.setTitle("下载jpg");
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
request.setMimeType("image/jpeg");
//实际下载后存放的路径并不一定是这个名字,如果有重名的,自动向名字中追加数字编号
File apkFile = new File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_DOWNLOADS + "/701483.apk");
request.setDestinationUri(Uri.fromFile(apkFile));
downloadId = dw.enqueue(request);
isDownloading = true;
Uri uri = dw.getDownloadUri(downloadId);
if (uri != null) {
progressBar.setMax(1000);
progressBar.setProgress(0);
if (observer != null) {
getContentResolver().unregisterContentObserver(observer);
observer = null;
}
observer = new DownloadStatusObserver();
getContentResolver().registerContentObserver(uri, true, observer);
}
} else if (v.getId() == R.id.pause) {
dw.pauseDownload(downloadId);
} else if (v.getId() == R.id.resume) {
dw.resumeDownload(downloadId);
}
}