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:Main.java

public static String getRootFolder() {
    return Environment.DIRECTORY_DOWNLOADS;
}

From source file:Main.java

public static String getDownload() {
    return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath()
            + "/";
}

From source file:Main.java

public static String getDownloadFolder() {
    return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
}

From source file:Main.java

public static String getDownloadFilePath() {
    return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath()
            + "/";
}

From source file:Main.java

public static File getDownloadDir(Context context) {
    return isExternalStorageWritable() ? context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
            : context.getFilesDir();//from   w w  w.  ja  va 2  s .  c  o m
}

From source file:Main.java

public static boolean writeToExternalStoragePublic(String filename, String fileContent) {
    boolean saved = false;
    String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/";
    if (isExternalStorageAvailable() && !isExternalStorageReadOnly()) {
        try {//w  ww  .j  a v a  2s.  c o  m
            boolean exists = (new File(path)).exists();
            if (!exists) {
                new File(path).mkdirs();
            }

            //Remote legacy file
            File file = new File(path + filename);
            file.delete();

            // Open output stream
            FileOutputStream fOut = new FileOutputStream(path + filename, true);
            fOut.write(fileContent.getBytes());
            // Close output stream
            fOut.flush();
            fOut.close();

            saved = true;
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return saved;
}

From source file:Main.java

public static String getDataDirectoryLocation() {
    return (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath());
}

From source file:Main.java

/**
 * Create a backup of the database./*w  ww . j a  v  a  2 s . c om*/
 *
 * @param context who calls the function.
 * @param dbName  Name of the database to backup. (If empty, radiomap.db is used).
 */
public static void exportDb(Context context, String dbName) {
    try {
        if (dbName.equals(""))
            dbName = "radiomap.db";

        File sd = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
        File data = Environment.getDataDirectory();

        if (sd.canWrite()) {
            String currentDBPath = "//data//" + context.getApplicationContext().getPackageName()
                    + "//databases//" + dbName;
            File currentDB = new File(data, currentDBPath);
            File backupDB = new File(sd, dbName);

            FileChannel src = new FileInputStream(currentDB).getChannel();
            FileChannel dst = new FileOutputStream(backupDB).getChannel();
            dst.transferFrom(src, 0, src.size());
            src.close();
            dst.close();

            Toast.makeText(context, "Datenbank nach Downloads exportiert!", Toast.LENGTH_LONG).show();
        }
    } catch (Exception e) {
        Log.e("Utils", e.getMessage());
        Toast.makeText(context, "Exportieren fehlgeschlagen!", Toast.LENGTH_LONG).show();
    }
}

From source file:Main.java

/**
 * Create a backup of the database./*from   w w w  . ja  v  a 2 s. c o m*/
 *
 * @param context who calls the function.
 * @param dbName  Name of the database to backup. (If empty, radiomap.db is used).
 */
public static void importDb(Context context, String dbName) {
    try {
        if (dbName.equals(""))
            dbName = "radiomap.db";

        File sd = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
        File data = Environment.getDataDirectory();

        if (sd.canWrite()) {
            String currentDBPath = "//data//" + context.getApplicationContext().getPackageName()
                    + "//databases//" + dbName;
            File backupDB = new File(data, currentDBPath);
            File currentDB = new File(sd, dbName);

            FileChannel src = new FileInputStream(currentDB).getChannel();
            FileChannel dst = new FileOutputStream(backupDB).getChannel();
            dst.transferFrom(src, 0, src.size());
            src.close();
            dst.close();

            Toast.makeText(context, "Datenbank von Downloads importiert!", Toast.LENGTH_LONG).show();
        }
    } catch (Exception e) {
        Log.e("Utils", e.getMessage());
        Toast.makeText(context, "Import fehlgeschlagen!", Toast.LENGTH_LONG).show();
    }
}

From source file:Main.java

/**
 * Get the External Downloads Directory to 
 * store the Selfies./*from ww  w  . ja v  a2s  . c om*/
 * 
 * @param ghostmyselfieName
 */
public static File getGhostMySelfieStorageDir(String ghostmyselfieName) {
    //Check to see if external SDCard is mounted or not.
    if (isExternalStorageWritable()) {
        // Create a path where we will place our selfie in the
        // user's public Downloads directory. Note that you should be
        // careful about what you place here, since the user often 
        // manages these files.
        final File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
        final File file = new File(path, ghostmyselfieName);
        // Make sure the Downloads directory exists.
        path.mkdirs();
        return file;
    } else {
        return null;
    }
}