List of usage examples for android.os Environment DIRECTORY_DOWNLOADS
String DIRECTORY_DOWNLOADS
To view the source code for android.os Environment DIRECTORY_DOWNLOADS.
Click Source Link
From source file:Main.java
public static Uri getLocalBitmapUri(ImageView imageView) { // Extract Bitmap from ImageView drawable Drawable drawable = imageView.getDrawable(); Bitmap bmp = null;/* ww w. j ava 2s.co m*/ if (drawable instanceof BitmapDrawable) { bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); } else { return null; } // Store image to default external storage directory Uri bmpUri = null; try { File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "share_image_" + System.currentTimeMillis() + ".png"); file.getParentFile().mkdirs(); FileOutputStream out = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.PNG, 90, out); out.close(); bmpUri = Uri.fromFile(file); } catch (IOException e) { e.printStackTrace(); } return bmpUri; }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.FROYO) private static File getDownloadDir_Froyo() { return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); }
From source file:Main.java
/** * @param context the context/*from ww w . j a va 2 s. c o m*/ * @param filename the filename * @return true if a file named "filename" is stored in the downloads directory */ public static Boolean doesFileExistInDownloads(Context context, String filename) { File dstDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); if (dstDir != null) { dstDir.mkdirs(); } File dstFile = new File(dstDir, filename); return dstFile.exists(); }
From source file:Main.java
public static File getLogPath(Context context) { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { File externalStorage = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); if (externalStorage == null) return null; return new File(externalStorage.getPath() + File.separatorChar + "logs"); }//from w w w . j av a 2s. c om return null; }
From source file:Main.java
public static File newFile() { Date date = new Date(); DateFormat dateFormat = new SimpleDateFormat("yy-MM-dd_HH-mm-ss", Locale.getDefault()); String filename = dateFormat.format(date) + ".jpg"; return new File( Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_DOWNLOADS + "/" + filename); }
From source file:Main.java
/** * Save a media URI into the download directory * @param context the context/* www .j av a 2 s. c om*/ * @param srcFile the source file. * @param filename the filename (optional) * @return the downloads file path */ @SuppressLint("NewApi") public static String saveMediaIntoDownloads(Context context, File srcFile, String filename, String mimeType) { String fullFilePath = saveFileInto(context, srcFile, Environment.DIRECTORY_DOWNLOADS, filename); if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { if (null != fullFilePath) { DownloadManager downloadManager = (DownloadManager) context .getSystemService(Context.DOWNLOAD_SERVICE); try { File file = new File(fullFilePath); downloadManager.addCompletedDownload(file.getName(), file.getName(), true, mimeType, file.getAbsolutePath(), file.length(), true); } catch (Exception e) { } } } return fullFilePath; }
From source file:org.proninyaroslav.libretorrent.core.utils.FileIOUtils.java
public static String getDefaultDownloadPath() { String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) .getAbsolutePath();/*from ww w . j a v a 2s .c o m*/ File dir = new File(path); if (dir.exists() && dir.isDirectory()) { return path; } else { return dir.mkdirs() ? path : ""; } }
From source file:Main.java
/** * Note: Make sure isDownloadManagerAvailable return is true before use this method. * @param apkName Apk File Name// w w w . j a va 2 s . co m * @param fullApkUrl url of full * @param context Context */ public static void downloadApkByDownloadManager(String apkName, String fullApkUrl, Context context) { DownloadManager.Request request = new DownloadManager.Request(Uri.parse(fullApkUrl)); request.setDescription(fullApkUrl); request.setTitle(apkName); // in order for this if to run, you must use the android 3.2 to compile your app if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { request.allowScanningByMediaScanner(); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); } request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, apkName); request.setVisibleInDownloadsUi(false); request.setMimeType("application/vnd.android.package-archive"); // get download service and enqueue file DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); manager.enqueue(request); }
From source file:com.abid_mujtaba.bitcoin.tracker.data.Data.java
private static File data_file() // Method for getting File object handle on the local data file { File dir = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + "/" + FOLDER); dir.mkdirs(); // Make the directory along with all necessary parent directories if they don't already exist return new File(dir, FILENAME); }
From source file:com.qasp.diego.arsp.Atualiza.java
public static boolean DownloadFTP() throws IOException { final String FTPURL = "37.187.45.24"; final String USUARIO = "diego"; final String SENHA = "Jogador5"; final String ARQUIVO = "data.dat"; FTPClient ftp = new FTPClient(); try {/*ww w. j a va 2 s . c o m*/ ftp.connect(FTPURL); ftp.login(USUARIO, SENHA); ftp.changeWorkingDirectory("/httpdocs/tcc/TCCpython"); ftp.setFileType(FTP.BINARY_FILE_TYPE); ftp.enterLocalPassiveMode(); OutputStream outputStream = null; boolean downloadcomsucesso = false; try { File f = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), ARQUIVO); f.createNewFile(); outputStream = new BufferedOutputStream(new FileOutputStream(f)); downloadcomsucesso = ftp.retrieveFile(ARQUIVO, outputStream); } finally { if (outputStream != null) outputStream.close(); } return downloadcomsucesso; } finally { if (ftp != null) { ftp.logout(); ftp.disconnect(); } } }