當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。