List of usage examples for android.os Environment getExternalStoragePublicDirectory
public static File getExternalStoragePublicDirectory(String type)
From source file:util.Utils.java
public static String getPictureStorageDirectory() { return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/" + Constant.CACHE_DIR;// w ww . j a v a 2 s . c om }
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 w ww . j a v a 2 s.c o m*/ v.setEnabled(false); query.setEnabled(true); }
From source file:com.networking.MyApplication.java
private void setVariableFromEnv() { try {//from w w w. j a v a2 s.com 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;// www . j a va 2 s . com 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.melchor629.musicote.Utils.java
public static String getUrl(String archivo) { File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC), archivo.substring(archivo.lastIndexOf("/") + 1)); if (file.exists()) return file.getAbsolutePath(); return String.format("http://%s%s%s", MainActivity.HOST, MainActivity.BASE_URL, archivo); }
From source file:com.pixby.texo.images.ImageUtil.java
private static String getAppStoragePath(String albumName) { File storageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), albumName);/*w w w .jav a 2 s . c o m*/ if (!storageDir.exists()) { if (!storageDir.mkdirs()) { Log.e(TAG, "getAppStoragePath mkdirs failed: " + storageDir.getAbsolutePath()); } } return storageDir.getPath(); }
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 w w w .j av a 2 s . c o m } 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:org.fashiontec.bodyapps.sync.SyncPic.java
/** * Gets path to save the images downloaded from API. * @param type/*from ww w . j av a 2 s . c o m*/ * @param id * @param picID * @return */ private File getOutputMediaFile(PicTypes type, String id, String picID) { String IMAGE_DIRECTORY_NAME = "BodyApp" + File.separator + id; File mediaStorageDir = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), IMAGE_DIRECTORY_NAME); // Create the storage directory if it does not exist if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { Log.d(IMAGE_DIRECTORY_NAME, "Oops! Failed create " + IMAGE_DIRECTORY_NAME + " directory"); return null; } } File mediaFile; String name = null; switch (type) { case FRONT: name = "front.jpg"; break; case SIDE: name = "side.jpg"; break; case BACK: name = "back.jpg"; break; case OTHER: name = picID + ".jpg"; break; } mediaFile = new File(mediaStorageDir.getPath() + File.separator + name); return mediaFile; }
From source file:com.melchor629.musicote.Utils.java
public static boolean isDownloaded(String archivo) { File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC), archivo.substring(archivo.lastIndexOf("/") + 1)); return file.exists(); }
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 . ja v a2 s . co m 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); }