Example usage for android.os Environment DIRECTORY_DOWNLOADS

List of usage examples for android.os Environment DIRECTORY_DOWNLOADS

Introduction

In this page you can find the example usage for android.os Environment DIRECTORY_DOWNLOADS.

Prototype

String DIRECTORY_DOWNLOADS

To view the source code for android.os Environment DIRECTORY_DOWNLOADS.

Click Source Link

Document

Standard directory in which to place files that have been downloaded by the user.

Usage

From source file:com.exercise.AndroidClient.RecvFrom.java

RecvFrom(DownloadManager downloadMgr, String json, String remoteHost) throws JSONException {
    this.downloadMgr = downloadMgr;
    this.remoteHost = remoteHost;
    this.json = json;
    parseJson(json);/*from  ww  w . jav  a  2s  .  c  om*/
    // setup map for getExternalStoragePublicDirectory values 
    destDirTypes = new HashMap<String, String>();
    destDirTypes.put("music", Environment.DIRECTORY_MUSIC);
    destDirTypes.put("downloads", Environment.DIRECTORY_DOWNLOADS);
    destDirTypes.put("pictures", Environment.DIRECTORY_PICTURES);
    destDirTypes.put("movies", Environment.DIRECTORY_MOVIES);
    valid = true;
}

From source file:com.commonsware.android.downloader.Downloader.java

@Override
public void onHandleIntent(Intent i) {
    try {/* w  ww  .ja v a2  s .  c  o m*/
        File root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);

        root.mkdirs();

        File output = new File(root, i.getData().getLastPathSegment());

        if (output.exists()) {
            output.delete();
        }

        URL url = new URL(i.getData().toString());
        HttpURLConnection c = (HttpURLConnection) url.openConnection();

        FileOutputStream fos = new FileOutputStream(output.getPath());
        BufferedOutputStream out = new BufferedOutputStream(fos);

        try {
            InputStream in = c.getInputStream();
            byte[] buffer = new byte[8192];
            int len = 0;

            while ((len = in.read(buffer)) >= 0) {
                out.write(buffer, 0, len);
            }

            out.flush();
        } finally {
            fos.getFD().sync();
            out.close();
            c.disconnect();
        }

        LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(ACTION_COMPLETE));
    } catch (IOException e2) {
        Log.e(getClass().getName(), "Exception in download", e2);
    }
}

From source file:com.commonsware.android.foredown.Downloader.java

@Override
public void onHandleIntent(Intent i) {
    try {/*  www  .ja  v  a2s  .  c  o m*/
        String filename = i.getData().getLastPathSegment();

        startForeground(FOREGROUND_ID, buildForegroundNotification(filename));

        File root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);

        root.mkdirs();

        File output = new File(root, filename);

        if (output.exists()) {
            output.delete();
        }

        URL url = new URL(i.getData().toString());
        HttpURLConnection c = (HttpURLConnection) url.openConnection();
        FileOutputStream fos = new FileOutputStream(output.getPath());
        BufferedOutputStream out = new BufferedOutputStream(fos);

        try {
            InputStream in = c.getInputStream();
            byte[] buffer = new byte[8192];
            int len = 0;

            while ((len = in.read(buffer)) >= 0) {
                out.write(buffer, 0, len);
            }

            out.flush();
        } finally {
            fos.getFD().sync();
            out.close();
            c.disconnect();
        }

        stopForeground(true);
        raiseNotification(i, output, null);
    } catch (IOException e2) {
        stopForeground(true);
        raiseNotification(i, null, e2);
    }
}

From source file:com.dycody.android.idealnote.utils.StorageHelper.java

public static String getStorageDir() {
    // return Environment.getExternalStorageDirectory() + File.separator +
    // Constants.TAG + File.separator;
    return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString();
}

From source file:de.yaacc.util.FileDownloader.java

@Override
protected Void doInBackground(DIDLObject... didlObjects) {
    if (didlObjects == null || didlObjects.length == 0 || didlObjects.length > 1) {
        throw new IllegalStateException("to less or many didlObjects....");
    }//from www. j  a  v  a2  s . c  om
    if (!isExternalStorageWritable()) {
        throw new IllegalStateException("External Storage is not writeable");
    }

    try {
        File storageDir = new File(
                Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/yaacc");
        if (!storageDir.exists()) {
            storageDir.mkdir();
        }
        createNotification(storageDir.getAbsolutePath());
        List<Item> items = upnpClient.toItemList(didlObjects[0]);
        for (Item item : items) {
            PlayableItem playableItem = new PlayableItem(item, 0);
            String filename = playableItem.getTitle().replace(" ", "");
            filename += "." + MimeTypeMap.getSingleton().getExtensionFromMimeType(playableItem.getMimeType());
            File file = new File(storageDir, filename);
            if (file.exists()) {
                int i = 1;
                while (file.exists()) {
                    filename = playableItem.getTitle().replace(" ", "") + "_" + i;
                    filename += "."
                            + MimeTypeMap.getSingleton().getExtensionFromMimeType(playableItem.getMimeType());
                    file = new File(storageDir, filename);
                    i++;
                }
            }

            try {

                InputStream is = new URL(playableItem.getUri().toString()).openStream();
                FileOutputStream outputStream = new FileOutputStream(file);
                byte[] b = new byte[1024];
                int len = 0;
                while ((len = is.read(b)) != -1) {
                    outputStream.write(b, 0, len);
                }
                is.close();
                outputStream.close();

            } catch (Exception e) {
                throw new RuntimeException(e);
            }

        }
    } finally {
        cancleNotification();
    }
    return null;
}

From source file:com.cyberocw.habittodosecretary.file.StorageHelper.java

public static String getStorageDir() {
    // return Environment.getExternalStorageDirectory() + File.separator +
    // Const.ERROR_TAG + File.separator;
    return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString();
}

From source file:butter.droid.base.fragments.dialog.FileSelectorDialogFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_dialog_fileselector, container);
    list = (ListView) view.findViewById(android.R.id.list);

    currentDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
    fill(currentDir);//from  ww w.j a  va  2 s.c o m

    return view;
}

From source file:com.albedinsky.android.support.intent.ContentIntentTest.java

public void testCreateContentFileNameInExternalDirectory() {
    final File file = ContentIntent.createContentFile("test-file.tmp", Environment.DIRECTORY_DOWNLOADS);
    assertNotNull(file);//from w  ww .jav  a2 s.  c o m
    assertTrue(file.exists());
    assertFileRelativePath("/Download/", file);
    assertTrue(file.delete());
}

From source file:com.qasp.diego.arsp.Atualiza.java

private static InputStream getArquivodeDados() throws IOException {

    final String NOME = "data.dat";
    File arquivo = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
            NOME);//ww w .  j  av a  2 s. c o m
    return (new FileInputStream(arquivo));
}

From source file:ufms.br.com.ufmsapp.task.DownloadTask.java

private void buildNotification() {
    manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    builder = new NotificationCompat.Builder(context);

    builder.setSmallIcon(iconResId);/*  w ww  . ja v  a  2s  . c o m*/
    builder.setContentTitle(fileName);
    builder.setContentText(msg);

    builder.setAutoCancel(true);

    Intent intent = new Intent();
    intent.setAction(android.content.Intent.ACTION_VIEW);
    File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
            fileName);
    intent.setDataAndType(Uri.fromFile(file),
            GetFileMimeType.getMimeType(title.replace(UPLOAD_PATH_REPLACE, "")));

    piOpenNotification = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(piOpenNotification);

    builder.setStyle(new NotificationCompat.BigTextStyle().bigText(msg));
}