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:com.tml.sharethem.receiver.FilesListingFragment.java
private long postDownloadRequestToDM(Uri uri, String fileName) { // Create request for android download manager DownloadManager downloadManager = (DownloadManager) getActivity().getSystemService(DOWNLOAD_SERVICE); DownloadManager.Request request = new DownloadManager.Request(uri); //Setting title of request request.setTitle(fileName);//w w w. j av a 2s.co m //Setting description of request request.setDescription("ShareThem"); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Set the local destination for the downloaded file to a path //within the application's external files directory request.setDestinationInExternalFilesDir(getActivity(), Environment.DIRECTORY_DOWNLOADS, fileName); //Enqueue download and save into referenceId return downloadManager.enqueue(request); }
From source file:com.ruesga.rview.misc.ActivityHelper.java
@SuppressWarnings("ResultOfMethodCallIgnored") public static void downloadUri(Context context, Uri uri, String fileName, @Nullable String mimeType) { // Create the destination location File destination = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); destination.mkdirs();//from w w w . java2 s.c o m Uri destinationUri = Uri.fromFile(new File(destination, fileName)); // Use the download manager to perform the download DownloadManager downloadManager = (DownloadManager) context.getSystemService(Activity.DOWNLOAD_SERVICE); Request request = new Request(uri).setNotificationVisibility(Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) .setDestinationUri(destinationUri); if (mimeType != null) { request.setMimeType(mimeType); } request.allowScanningByMediaScanner(); downloadManager.enqueue(request); }
From source file:activity.DetailsActivity.java
/** * Opens the document if it is on storage, else downloads it before open it. * /*from ww w. j a v a2 s . c o m*/ * @param item * the document to open */ public void openFileInMemory(final Document item) { mItem = item; MimeTypeMap map = MimeTypeMap.getSingleton(); final String mime = map.getMimeTypeFromExtension(item.getExtension()); mSubPath = item.getTitle() + "." + item.getExtension(); if (mime != null) { if (item.isOnMemory() && Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(Environment.getExternalStorageState())) { Intent i = new Intent(Intent.ACTION_VIEW); i.setDataAndType(Uri.fromFile( new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) .getAbsolutePath() + "/" + mSubPath)), mime.toLowerCase(Locale.US)); startActivity(Intent.createChooser(i, getString(R.string.dialog_choose_app))); } else { getService().getDownloadTokenizedUrl(item.getList().getCours().getSysCode(), item.getResourceString(), mDwlManagerHandler); } } else { DetailsActivity.this.getService().getDownloadTokenizedUrl(item.getList().getCours().getSysCode(), item.getResourceString(), mTokenizedURLHandler); } }
From source file:com.bt.heliniumstudentapp.UpdateClass.java
protected static void downloadAPK() { File oldUpdate = new File(Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_DOWNLOADS + "/heliniumstudentapp.apk"); if (oldUpdate.exists()) //noinspection ResultOfMethodCallIgnored oldUpdate.delete();/*from ww w .j a v a 2 s. co m*/ if (MainActivity.isOnline()) { DownloadManager.Request request; request = new DownloadManager.Request(Uri.parse(HeliniumStudentApp.URL_UPDATE_RELEASE)); request.setTitle(context.getString(R.string.app_name) + " " + versionName); request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "/heliniumstudentapp.apk"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); ((DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(request); context.registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { final Intent install = new Intent(Intent.ACTION_VIEW); install.setDataAndType( Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_DOWNLOADS + "/heliniumstudentapp.apk")), "application/vnd.android.package-archive"); context.startActivity(install); } }, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); } else { Toast.makeText(context, R.string.error_conn_no, Toast.LENGTH_SHORT).show(); } }
From source file:es.usc.citius.servando.calendula.fragments.MedicinesListFragment.java
private void openProspect(Prescription p) { File f = new File(getActivity().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + "/prospects/" + p.pid + ".pdf"); File file = new File(f.getAbsolutePath()); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "application/pdf"); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); startActivity(intent);/* w w w . j a v a 2s . c o m*/ }
From source file:com.google.android.gms.samples.vision.face.facetracker.FaceGraphic.java
public void audioPlayer(String fileName) { //set up MediaPlayer if (!setupDone) { try {//w w w . ja va2 s. c o m File downloadDir = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) .getAbsolutePath() + File.separator + fileName); File[] downloadDirs = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) .listFiles(); //File exdir = Environment.getExternalStorageDirectory(); //System.out.println("EXDIR!!!!!!!!!: " + exdir); for (File tmpf : downloadDirs) { System.out.println("FILE: " + tmpf.getAbsolutePath()); } File file = new File("/storage/emulated/0/downloads" + File.separator + fileName); FileInputStream inputStream = new FileInputStream(downloadDir); mp.setDataSource(inputStream.getFD()); mp.prepare(); setupDone = true; } catch (Exception e) { System.out.println("ERROR READING MUSIC: " + e.getMessage()); e.printStackTrace(); } } }
From source file:com.coinblesk.client.backup.BackupDialogFragment.java
private File newWalletBackupFile() { File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); File walletFile = null;/*from w w w.j a v a 2s . co m*/ for (int i = 0;; ++i) { String currentTime = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date()); String postfix = i > 0 ? String.format("_%d", i) : ""; String fileName = String.format("%s_%s%s", Constants.BACKUP_FILE_PREFIX, currentTime, postfix); walletFile = new File(path, fileName); if (!walletFile.exists()) { return walletFile; } } }
From source file:com.ruesga.rview.misc.ActivityHelper.java
public static void downloadLocalFile(Context context, File src, String name) throws IOException { File downloadFolder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); File dst = new File(downloadFolder, name); FileUtils.copyFile(src, dst);//w w w . j a v a 2s . c om String mimeType = StringHelper.getMimeType(dst); DownloadManager downloadManager = (DownloadManager) context.getSystemService(Activity.DOWNLOAD_SERVICE); downloadManager.addCompletedDownload(dst.getName(), dst.getName(), true, mimeType, dst.getPath(), dst.length(), true); }
From source file:net.fabiszewski.ulogger.GpxExportService.java
/** * Set up directory in Downloads folder//from w w w .j av a 2 s. co m * * @return File instance or null in case of failure */ private File getDir() { File dir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), ULOGGER_DIR); if (!dir.exists() && !dir.mkdirs()) { dir = null; } return dir; }
From source file:dev.dworks.apps.anexplorer.provider.ExternalStorageProvider.java
private void includeOtherRoot() { try {//from w w w . ja v a 2s . c o m final String rootId = ROOT_ID_PHONE; final File path = new File(DIR_ROOT); mIdToPath.put(rootId, path); final RootInfo root = new RootInfo(); root.rootId = rootId; root.flags = Root.FLAG_LOCAL_ONLY | Root.FLAG_ADVANCED | Root.FLAG_SUPER_ADVANCED | Root.FLAG_SUPPORTS_SEARCH; root.title = getContext().getString(R.string.root_phone_storage); root.docId = getDocIdForFile(path); root.path = path.getPath(); mRoots.add(root); mIdToRoot.put(rootId, root); } catch (FileNotFoundException e) { e.printStackTrace(); } try { final String rootId = ROOT_ID_DOWNLOAD; final File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); mIdToPath.put(rootId, path); final RootInfo root = new RootInfo(); root.rootId = rootId; root.flags = Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_EDIT | Root.FLAG_LOCAL_ONLY | Root.FLAG_ADVANCED | Root.FLAG_SUPPORTS_SEARCH; root.title = getContext().getString(R.string.root_downloads); root.docId = getDocIdForFile(path); root.path = path.getPath(); mRoots.add(root); mIdToRoot.put(rootId, root); } catch (FileNotFoundException e) { e.printStackTrace(); } try { final String rootId = ROOT_ID_APP_BACKUP; final File path = Environment.getExternalStoragePublicDirectory("AppBackup"); mIdToPath.put(rootId, path); final RootInfo root = new RootInfo(); root.rootId = rootId; root.flags = Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_EDIT | Root.FLAG_LOCAL_ONLY | Root.FLAG_ADVANCED | Root.FLAG_SUPPORTS_SEARCH; root.title = getContext().getString(R.string.root_app_backup); root.docId = getDocIdForFile(path); root.path = path.getPath(); mRoots.add(root); mIdToRoot.put(rootId, root); } catch (FileNotFoundException e) { e.printStackTrace(); } try { final String rootId = ROOT_ID_BLUETOOTH; File path = Environment.getExternalStoragePublicDirectory("Bluetooth"); if (null == path) { path = Environment.getExternalStoragePublicDirectory("Download/Bluetooth"); } if (null != path) { mIdToPath.put(rootId, path); final RootInfo root = new RootInfo(); root.rootId = rootId; root.flags = Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_EDIT | Root.FLAG_LOCAL_ONLY | Root.FLAG_ADVANCED | Root.FLAG_SUPPORTS_SEARCH; root.title = getContext().getString(R.string.root_bluetooth); root.docId = getDocIdForFile(path); root.path = path.getPath(); mRoots.add(root); mIdToRoot.put(rootId, root); } } catch (FileNotFoundException e) { e.printStackTrace(); } }