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


Java Environment.DIRECTORY_DOWNLOADS属性代码示例

本文整理汇总了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);
    }
}
 
开发者ID:redleaf2002,项目名称:downloadmanager,代码行数:23,代码来源:Helpers.java

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

示例3: dirChecker

private static void dirChecker(String dir) {
    File f = new File(Environment.DIRECTORY_DOWNLOADS + dir);

    if(!f.isDirectory()) {
        f.mkdirs();
    }
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:7,代码来源:FileUtils.java

示例4: getDownloadDir

public static File getDownloadDir() throws NoExternalStorageException {
  return new File(getSignalStorageDir(), Environment.DIRECTORY_DOWNLOADS);
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:3,代码来源:StorageUtil.java

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

}
 
开发者ID:limpoxe,项目名称:Android-DownloadManager,代码行数:45,代码来源:MainActivity.java


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