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.commonsware.android.downmgr.DownloadFragment.java
private void startDownload(View v) { Uri uri = Uri.parse("https://commonsware.com/misc/test.mp4"); Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).mkdirs(); DownloadManager.Request req = new DownloadManager.Request(uri); req.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE) .setAllowedOverRoaming(false).setTitle("Demo").setDescription("Something useful. No, really.") .setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "test.mp4"); lastDownload = mgr.enqueue(req);/*from ww w . ja v a 2 s. co m*/ v.setEnabled(false); query.setEnabled(true); }
From source file:com.networking.MyApplication.java
private void setVariableFromEnv() { try {// ww w . j a v a 2s . c om File sdcard = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); File file = new File(sdcard, "env.txt"); if (!file.exists()) { Log.d(TAG, "Env file is not present in download folder"); Toast.makeText(getApplicationContext(), "Env file is not present in download folder", Toast.LENGTH_LONG).show(); return; } StringBuilder text = new StringBuilder(); try { BufferedReader br = new BufferedReader(new FileReader(file)); String line; while ((line = br.readLine()) != null) { text.append(line); text.append('\n'); } br.close(); try { JSONObject jsonObject = new JSONObject(text.toString()); ApiEndPoint.BASE_URL = jsonObject.getString("baseUrl"); ApiEndPoint.UPLOAD_IMAGE_URL = jsonObject.getString("uploadImageUrl"); } catch (JSONException e) { Log.d(TAG, "Check env file json in download folder"); Toast.makeText(getApplicationContext(), "Check env file json in download folder", Toast.LENGTH_LONG).show(); } } catch (IOException e) { Log.d(TAG, "Check env file in download folder"); Toast.makeText(getApplicationContext(), "Check env file in download folder", Toast.LENGTH_LONG) .show(); } } catch (Exception e) { Log.d(TAG, "Exception in loading settingVariableFromEnv"); Toast.makeText(getApplicationContext(), "Exception in loading settingVariableFromEnv", Toast.LENGTH_LONG).show(); } }
From source file:org.amahi.anywhere.util.Downloader.java
private void startDownloading(Uri downloadUri, String downloadName, @FileOption.Types int fileOption) { File file;//w w w .j ava2 s . co m DownloadManager.Request downloadRequest = new DownloadManager.Request(downloadUri); if (fileOption == FileOption.DOWNLOAD) { // download in public directory file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), downloadName); downloadRequest.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, downloadName); } else { // download in App directory file = new File(context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), downloadName); downloadRequest.setDestinationInExternalFilesDir(context, Environment.DIRECTORY_DOWNLOADS, downloadName); } //code to delete the file if it already exists if (file.exists()) file.delete(); downloadRequest.setVisibleInDownloadsUi(true) .setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN); this.downloadId = getDownloadManager(context).enqueue(downloadRequest); }
From source file:com.haha01haha01.harail.DatabaseDownloader.java
@Override protected void onHandleIntent(Intent workIntent) { PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, NAME); NotificationManager notifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Notification.Builder builder = new Notification.Builder(this); builder.setContentTitle("HaRail GTFS Database").setContentText("Downloading file") .setSmallIcon(android.R.drawable.ic_popup_sync).setProgress(0, 0, true); notifyManager.notify(1, builder.build()); wakeLock.acquire();/*from w w w. j av a 2 s . co m*/ try { String filename = "harail_irw_gtfs_" + Utils.getCurrentDateString() + ".zip"; File zip_file = new File( new File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_DOWNLOADS), filename); if (downloadFile(irw_gtfs_server, irw_gtfs_port, "anonymous", "", irw_gtfs_filename, zip_file)) { sendFinished(extractDb(zip_file, notifyManager, builder)); } else { sendFinished(false); } wakeLock.release(); } catch (IOException e) { sendFinished(false); builder.setContentText("Download failed").setSmallIcon(android.R.drawable.ic_dialog_alert) .setProgress(0, 0, false); notifyManager.notify(1, builder.build()); wakeLock.release(); } }
From source file:cn.devit.app.ip_messenger.DownloadTask.java
@Override protected Integer doInBackground(PigeonMessage... params) { long got = 0;// store all file's byte size. int count = 0;// store number of files received. for (PigeonMessage item : params) { for (int i = 0; i < item.getAttachements().size(); i++) { size += item.getAttachements().get(i).getLength(); }//from www . j a v a 2s . com } Log.d("main", "total bytes of file:" + size); // TODO ?publish for (PigeonMessage item : params) { for (int i = 0; i < item.getAttachements().size(); i++) { noteId = item.hashCode(); AttachementLink link = item.getAttachements().get(i); if (link.getType() == PigeonCommand.IPMSG_FILE_REGULAR) { count++; Socket socket = null; try { socket = network.getAttachementStream(item, i); } catch (IOException e) { e.printStackTrace(); continue; } InputStream stream = null; try { stream = socket.getInputStream(); } catch (IOException e) { e.printStackTrace(); continue; } File download = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); String filename = link.getFilename(); File file = new File(download, filename); if (file.exists()) { file.delete(); } else { try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } Log.d("main", "download file:" + file.getName()); try { FileOutputStream fos = new FileOutputStream(file); byte[] cache = new byte[1024]; try { int len = 0; while ((len = stream.read(cache)) >= 0) { got += len; fos.write(cache, 0, len); this.publishProgress(got); } fos.close(); stream.close(); socket.close(); } catch (IOException e) { e.printStackTrace(); } } catch (FileNotFoundException e) { e.printStackTrace(); } } // try { // } catch (IOException e) { // if(socket!=null){ // socket. // } // } } } // TODO Auto-generated method stub return count; }
From source file:com.github.se_bastiaan.torrentstreamer.sample.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); String action = getIntent().getAction(); Uri data = getIntent().getData();// w w w .j ava 2s.c om if (action != null && action.equals(Intent.ACTION_VIEW) && data != null) { try { streamUrl = URLDecoder.decode(data.toString(), "utf-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } TorrentOptions torrentOptions = new TorrentOptions.Builder() .saveLocation(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)) .removeFilesAfterStop(true).build(); torrentStream = TorrentStream.init(torrentOptions); torrentStream.addListener(this); button = (Button) findViewById(R.id.button); button.setOnClickListener(onClickListener); progressBar = (ProgressBar) findViewById(R.id.progress); progressBar.setMax(100); }
From source file:br.ufrn.dimap.pubshare.download.service.DownloaderService.java
/** * The IntentService calls this method from the default worker thread with * the intent that started the service. When this method returns, IntentService * stops the service, as appropriate./* w w w.ja va 2 s .co m*/ */ @Override protected void onHandleIntent(Intent intent) { Log.d(TAG, "onHandleIntent on DownloadService"); Article selectedArticle = (Article) intent.getSerializableExtra(Article.KEY_INSTANCE); if (!AndroidUtils.isExternalStorageAvailable()) { // Generate Menssages NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_menu_notifications) .setContentTitle(getResources().getString(R.string.external_storage_unavailable)) .setContentText(getResources().getString(R.string.check_media_availability)); Notification notification = mBuilder.build(); // Set the Notification as ongoing notification.flags = notification.flags | Notification.FLAG_AUTO_CANCEL; NotificationManager nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nManager.notify(0, notification); return; } DownloadManager dowloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); // since API level 9 Request request = new Request(Uri.parse(selectedArticle.getRemoteLocation())); request.setAllowedNetworkTypes(Request.NETWORK_WIFI | Request.NETWORK_MOBILE); request.setTitle(selectedArticle.getTitle()); request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, selectedArticle.generateFileName()); request.setVisibleInDownloadsUi(true); long enqueue = dowloadManager.enqueue(request); Log.d(TAG, "Download enqueue..." + enqueue); ArticleDownloaded articleDownloaded = new ArticleDownloaded(); articleDownloaded.setDownloadKey(enqueue); DownloadDao downloadDao = new DownloadDao(this); downloadDao.insert(articleDownloaded); Log.d(TAG, "Insert " + articleDownloaded + " in SqLite: OK"); }
From source file:com.concentricsky.android.khanacademy.util.ThumbnailManager.java
private DiskLruCache prepareDiskCache() { int v = 0;//from w ww .j a va2 s .c o m try { v = dataService.getPackageManager().getPackageInfo(dataService.getPackageName(), 0).versionCode; } catch (NameNotFoundException e) { // Huh? Really? } // TODO : allow user to configure this. long maxSize = 1024 * 1024 * 1024; File cacheDir = new File(dataService.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), "thumbnail_cache"); int valueCount = 8; try { // TODO : This is slow on first run. Look into improving that. return DiskLruCache.open(cacheDir, v, valueCount, maxSize); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:com.example.locationproject.wifidirect.WiFiDirectActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);//w w w.j a v a 2 s . c o m // add necessary intent values to be matched. intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION); manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE); channel = manager.initialize(this, getMainLooper(), null); Log.d(TAG, "Deleting healthplus folder at slave"); File f = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + "/location"); if (f.exists()) { try { FileUtils.deleteDirectory(f); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { Log.d("WifiDirectActivity", "downloads folder for slave is empty"); } Log.d("WifiDirectACtivity", "calling FileLocatoe service"); Intent i = new Intent(this, FileLocator.class); // Add extras to the bundle //i.putExtra("foo", "bar"); // Start the service startService(i); }
From source file:com.example.healthplus.wifidirect.WiFiDirectActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);//from w w w . j ava2 s. c om // add necessary intent values to be matched. intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION); manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE); channel = manager.initialize(this, getMainLooper(), null); Log.d(TAG, "Deleting healthplus folder at slave"); File f = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + "/healthplus"); if (f.exists()) { try { FileUtils.deleteDirectory(f); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { Log.d("WifiDirectActivity", "downloads folder for slave is empty"); } Intent i = new Intent(this, FileLocator.class); // Add extras to the bundle //i.putExtra("foo", "bar"); // Start the service startService(i); }