Java Code Examples for android.os.Environment#DIRECTORY_DOWNLOADS

The following examples show how to use android.os.Environment#DIRECTORY_DOWNLOADS . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
public void addCommonBookmarks() {
    String sd = Environment.getExternalStorageDirectory() + "/";

    String[] dirs = new String[] {
            sd + Environment.DIRECTORY_DCIM,
            sd + Environment.DIRECTORY_DOWNLOADS,
            sd + Environment.DIRECTORY_MOVIES,
            sd + Environment.DIRECTORY_MUSIC,
            sd + Environment.DIRECTORY_PICTURES
    };

    for (String dir : dirs) {

        addBookmark(new File(dir).getName(), dir);
    }
}
 
Example 2
private String getDirectoryName(String name) {
    switch (name) {
        case "ALARMS":
            return Environment.DIRECTORY_ALARMS;
        case "DCIM":
            return Environment.DIRECTORY_DCIM;
        case "DOCUMENTS":
            return Environment.DIRECTORY_DOCUMENTS;
        case "DOWNLOADS":
            return Environment.DIRECTORY_DOWNLOADS;
        case "MOVIES":
            return Environment.DIRECTORY_MOVIES;
        case "MUSIC":
            return Environment.DIRECTORY_MUSIC;
        case "NOTIFICATIONS":
            return Environment.DIRECTORY_NOTIFICATIONS;
        case "PICTURES":
            return Environment.DIRECTORY_PICTURES;
        case "PODCASTS":
            return Environment.DIRECTORY_PODCASTS;
        case "RINGTONES":
            return Environment.DIRECTORY_RINGTONES;
        default:
            throw new IllegalArgumentException("Invalid directory representation: " + name);
    }
}
 
Example 3
@Test
public void testGetters() {
    final Download download = new Download(
            "https://www.mozilla.org/image.png",
            "Focus/1.0",
            "Content-Disposition: attachment; filename=\"filename.png\"",
            "image/png",
            1024,
            Environment.DIRECTORY_DOWNLOADS,
            fileName);

    assertEquals("https://www.mozilla.org/image.png", download.getUrl());
    assertEquals("Focus/1.0", download.getUserAgent());
    assertEquals("Content-Disposition: attachment; filename=\"filename.png\"", download.getContentDisposition());
    assertEquals("image/png", download.getMimeType());
    assertEquals(1024, download.getContentLength());
    assertEquals(Environment.DIRECTORY_DOWNLOADS, download.getDestinationDirectory());
    assertEquals(fileName, download.getFileName());
}
 
Example 4
Source Project: travelguide   File: Expansion.java    License: Apache License 2.0 6 votes vote down vote up
public static String findPackageObbFile(String packageName)
{
  final String[] pathsToLook = { getObbLocation(packageName),
                                 // For development purpose - obbs can be in MWM folder, if MWM is installed too
                                 Environment.getExternalStorageDirectory() + File.separator + "MapsWithMe",
                                 // For user-testing, to directly download obb to the device by http link
                                 Environment.getExternalStorageDirectory() + File.separator + Environment.DIRECTORY_DOWNLOADS };
  for (final String pathToLook : pathsToLook)
  {
    final File obbDir = new File(pathToLook);
    if (!obbDir.exists())
      continue;
    final String[] filesInDir = obbDir.list();
    for (final String fileName : filesInDir)
      if (fileName.endsWith(packageName + ".obb"))
        return obbDir.getAbsolutePath() + File.separator + fileName;
  }
  // obb was not found :(
  return null;
}
 
Example 5
@Nullable
private String getOutputPathForJob(@NonNull DownloadJob job) {
    File outputFolder =  new File(mContext.getExternalFilesDir(null), Environment.DIRECTORY_DOWNLOADS);
    if (outputFolder.exists() || (!outputFolder.exists() && outputFolder.mkdir())) {
        File outputFile = new File(outputFolder, job.getFilename());
        return "file://" + outputFile.getAbsolutePath();
    }

    return null;
}
 
Example 6
Source Project: microbit   File: FileUtils.java    License: Apache License 2.0 5 votes vote down vote up
private static void dirChecker(String dir) {
    File f = new File(Environment.DIRECTORY_DOWNLOADS + dir);

    if(!f.isDirectory()) {
        f.mkdirs();
    }
}
 
Example 7
@Test
public void listFilesZeroFiles() throws Exception {

    File tempFile = new File(Environment.DIRECTORY_DOWNLOADS);
    File directory = new File(tempFile, "rajababu");
    directory.mkdir();

    ArrayList files = new ArrayList();
    FileUtils.listFiles(directory, files);

    assertEquals(0, files.size());

    // clean up
    directory.delete();
}
 
Example 8
Source Project: react-native-share   File: ShareFiles.java    License: MIT License 5 votes vote down vote up
public ArrayList<Uri> getURI() {
    final MimeTypeMap mime = MimeTypeMap.getSingleton();
    ArrayList<Uri> finalUris = new ArrayList<>();

    for (int uriIndex = 0; uriIndex < this.uris.size(); uriIndex++) {
        Uri uri = this.uris.get(uriIndex);

        if(this.isBase64File(uri)) {
            String type = uri.getSchemeSpecificPart().substring(0, uri.getSchemeSpecificPart().indexOf(";"));
            String extension = mime.getExtensionFromMimeType(type);
            String encodedImg = uri.getSchemeSpecificPart().substring(uri.getSchemeSpecificPart().indexOf(";base64,") + 8);
            String fileName = filenames.size() >= uriIndex + 1 ? filenames.get(uriIndex) : (System.currentTimeMillis() + "." + extension);
            try {
                File dir = new File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_DOWNLOADS );
                if (!dir.exists() && !dir.mkdirs()) {
                    throw new IOException("mkdirs failed on " + dir.getAbsolutePath());
                }
                File file = new File(dir, fileName);
                final FileOutputStream fos = new FileOutputStream(file);
                fos.write(Base64.decode(encodedImg, Base64.DEFAULT));
                fos.flush();
                fos.close();
                finalUris.add(RNSharePathUtil.compatUriFromFile(reactContext, file));
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else if(this.isLocalFile(uri)) {
            if (uri.getPath() != null) {
                if (filenames.size() >= uriIndex + 1) {
                    finalUris.add(RNSharePathUtil.compatUriFromFile(reactContext, new File(uri.getPath(), filenames.get(uriIndex))));
                } else {
                    finalUris.add(RNSharePathUtil.compatUriFromFile(reactContext, new File(uri.getPath())));
                }
            }
        }
    }

    return finalUris;
}
 
Example 9
public static String getStorageDirectory(Context mContext) {
    File path = null;
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        Log.w("[File Utils] External storage is mounted");
        String directory = Environment.DIRECTORY_DOWNLOADS;
        path = mContext.getExternalFilesDir(directory);
    }

    if (path == null) {
        Log.w("[File Utils] Couldn't get external storage path, using internal");
        path = mContext.getFilesDir();
    }

    return path.getAbsolutePath();
}
 
Example 10
Source Project: RxDownloader   File: RxDownloader.java    License: MIT License 5 votes vote down vote up
private DownloadManager.Request createRequest(@NonNull String url,
                                              @NonNull String filename,
                                              @Nullable String destinationPath,
                                              @NonNull String mimeType,
                                              boolean inPublicDir,
                                              boolean showCompletedNotification) {

    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
    request.setDescription(filename);
    request.setMimeType(mimeType);

    if (destinationPath == null) {
        destinationPath = Environment.DIRECTORY_DOWNLOADS;
    }

    File destinationFolder = inPublicDir
            ? Environment.getExternalStoragePublicDirectory(destinationPath)
            : new File(context.getFilesDir(), destinationPath);

    createFolderIfNeeded(destinationFolder);
    removeDuplicateFileIfExist(destinationFolder, filename);

    if (inPublicDir) {
        request.setDestinationInExternalPublicDir(destinationPath, filename);
    } else {
        request.setDestinationInExternalFilesDir(context, destinationPath, filename);
    }

    request.setNotificationVisibility(showCompletedNotification
            ? DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED
            : DownloadManager.Request.VISIBILITY_VISIBLE);

    return request;
}
 
Example 11
public static File getDownloadDir() throws NoExternalStorageException {
  return new File(getSignalStorageDir(), Environment.DIRECTORY_DOWNLOADS);
}
 
Example 12
public static File getDownloadDir() throws NoExternalStorageException {
    return new File(getExternalStorageDir(), Environment.DIRECTORY_DOWNLOADS);
}
 
Example 13
public static File getDownloadDir() throws NoExternalStorageException {
  return new File(getStorageDir(), Environment.DIRECTORY_DOWNLOADS);
}
 
Example 14
Source Project: LyricHere   File: FileUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static File getDownloadsFolder() {
    return new File("/sdcard/" + Environment.DIRECTORY_DOWNLOADS);
}