List of usage examples for android.os Environment getExternalStoragePublicDirectory
public static File getExternalStoragePublicDirectory(String type)
From source file:es.upv.riromu.arbre.main.MainActivity.java
@Override protected void onSaveInstanceState(Bundle outState) { FileOutputStream fos;//w w w. j a v a 2 s . c o m if (image != null) { try { String fileName = "temp_image.jpg"; String fileURL = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) .getPath() + "/" + fileName; fos = new FileOutputStream(fileURL); image.compress(Bitmap.CompressFormat.JPEG, compressRatio, fos); outState.putBoolean("image", true); image.recycle(); System.gc(); } catch (Exception e) { Log.e(TAG, "Error " + e.getMessage()); } } if (state[CROP_IMAGE]) { try { String fileName = "temp_cropped.jpg"; String fileURL = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) .getPath() + "/" + fileName; fos = new FileOutputStream(fileURL); croppedimage.compress(Bitmap.CompressFormat.JPEG, 100, fos); outState.putBoolean("croppedimage", true); fos.close(); croppedimage.recycle(); System.gc(); } catch (Exception e) { Log.e(TAG, "Error " + e.getMessage()); } } if (state[TREAT_IMAGE]) { try { String fileName = "temp_treated.jpg"; String fileURL = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) .getPath() + "/" + fileName; fos = new FileOutputStream(fileURL); ImageView imv = (ImageView) findViewById(R.id.image_intro); ((BitmapDrawable) imv.getDrawable()).getBitmap().compress(Bitmap.CompressFormat.JPEG, 100, fos); outState.putBoolean("treatedimage", true); fos.close(); } catch (Exception e) { Log.e(TAG, "Error " + e.getMessage()); } } if (image_uri != null) { outState.putString("image_uri", image_uri.getPath()); } outState.putIntArray("colours", colours); outState.putBoolean("cropping", state[CROP_IMAGE]); outState.putBoolean("treated", state[TREAT_IMAGE]); super.onSaveInstanceState(outState); }
From source file:com.giovanniterlingen.windesheim.view.Adapters.NatschoolContentAdapter.java
private void showPromptDialog(final int position) { new AlertDialog.Builder(activity).setTitle(activity.getResources().getString(R.string.confirmation)) .setMessage(activity.getResources().getString(R.string.delete_file_description)) .setPositiveButton(activity.getResources().getString(R.string.delete), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { File directory = Environment .getExternalStoragePublicDirectory(ApplicationLoader.applicationContext .getResources().getString(R.string.app_name)); File file = new File(directory, content.get(position).name); if (file.exists()) { file.delete(); }//from w w w . j av a 2 s . co m content.remove(position); notifyItemRemoved(position); if (content.size() == 0) { ((DownloadsActivity) activity).showEmptyTextview(); } Snackbar snackbar = Snackbar.make(activity.findViewById(R.id.coordinator_layout), activity.getResources().getString(R.string.file_deleted), Snackbar.LENGTH_SHORT); snackbar.show(); dialog.cancel(); } }) .setNegativeButton(activity.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }) .show(); }
From source file:com.coinblesk.client.backup.BackupDialogFragment.java
private File newWalletBackupFile() { File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); File walletFile = null;/*w w w . j ava 2 s .c om*/ 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);//from w w w. ja v a 2 s.c o m 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:com.my.seams_carv.StartActivity.java
private File createImageFile() throws IOException { String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.ENGLISH).format(new Date()); final String appName = getResources().getString(R.string.app_name); final File dir = Environment .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES + "/" + appName); // Create the missing parents. if (dir.mkdirs() || dir.isDirectory()) { return File.createTempFile(timeStamp, ".jpg", dir); } else {/*w ww. ja v a 2 s. co m*/ throw new IOException(String.format("%s is not present.", dir.getAbsolutePath())); } }
From source file:ca.frozen.curlingtv.classes.Utils.java
public static String saveImage(ContentResolver contentResolver, Bitmap source, String title, String description) {/*www . java 2s . c o m*/ File snapshot = null; Uri url = null; try { // get/create the snapshots folder File pictures = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File rpi = new File(pictures, App.getStr(R.string.app_name)); if (!rpi.exists()) { rpi.mkdir(); } // save the file within the snapshots folder snapshot = new File(rpi, title); OutputStream stream = new FileOutputStream(snapshot); source.compress(Bitmap.CompressFormat.JPEG, 90, stream); stream.flush(); stream.close(); // create the content values ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, title); values.put(MediaStore.Images.Media.DISPLAY_NAME, title); if (description != null) { values.put(MediaStore.Images.Media.DESCRIPTION, description); } values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); values.put(MediaStore.Images.Media.DATE_ADDED, System.currentTimeMillis()); values.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis()); values.put(MediaStore.Images.ImageColumns.BUCKET_ID, snapshot.toString().toLowerCase(Locale.US).hashCode()); values.put(MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME, snapshot.getName().toLowerCase(Locale.US)); values.put("_data", snapshot.getAbsolutePath()); // insert the image into the database url = contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); } catch (Exception ex) { return null; } // return the URL return (url != null) ? url.toString() : null; }
From source file:net.fabiszewski.ulogger.GpxExportService.java
/** * Set up directory in Downloads folder/*from w ww .j a v a 2 s . c o 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 ww w . j a v a2s . com 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(); } }
From source file:com.wondertoys.pokevalue.utils.AutoUpdateApk.java
private void setupVariables(Context ctx) { context = ctx;//from w w w . ja v a 2 s.com packageName = context.getPackageName(); preferences = context.getSharedPreferences(packageName + "_" + TAG, Context.MODE_PRIVATE); device_id = crc32(Secure.getString(context.getContentResolver(), Secure.ANDROID_ID)); last_update = preferences.getLong("last_update", 0); NOTIFICATION_ID += crc32(packageName); // schedule.add(new ScheduleEntry(0,24)); ApplicationInfo appinfo = context.getApplicationInfo(); if (appinfo.icon != 0) { appIcon = appinfo.icon; } else { Log_w(TAG, "unable to find application icon"); } if (appinfo.labelRes != 0) { appName = context.getString(appinfo.labelRes); } else { Log_w(TAG, "unable to find application label"); } if (new File(appinfo.sourceDir).lastModified() > preferences.getLong(MD5_TIME, 0)) { preferences.edit().putString(MD5_KEY, MD5Hex(appinfo.sourceDir)).commit(); preferences.edit().putLong(MD5_TIME, System.currentTimeMillis()).commit(); String update_file = preferences.getString(UPDATE_FILE, ""); if (update_file.length() > 0) { if (new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/" + update_file).delete()) { preferences.edit().remove(UPDATE_FILE).remove(SILENT_FAILED).commit(); } } } raise_notification(); if (haveInternetPermissions()) { context.registerReceiver(connectivity_receiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); } }
From source file:biz.bokhorst.xprivacy.Util.java
public static String[] getProLicenseUnchecked() { // Get license file name String storageDir = Environment.getExternalStorageDirectory().getAbsolutePath(); File licenseFile = new File(storageDir + File.separator + LICENSE_FILE_NAME); if (!licenseFile.exists()) licenseFile = new File(storageDir + File.separator + ".xprivacy" + File.separator + LICENSE_FILE_NAME); if (!licenseFile.exists()) licenseFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + File.separator + LICENSE_FILE_NAME); String importedLicense = importProLicense(licenseFile); if (importedLicense == null) return null; // Check license file licenseFile = new File(importedLicense); if (licenseFile.exists()) { // Read license try {/*from ww w. j a va2 s. com*/ IniFile iniFile = new IniFile(licenseFile); String name = iniFile.get("name", ""); String email = iniFile.get("email", ""); String signature = iniFile.get("signature", ""); if (name == null || email == null || signature == null) return null; else { // Check expiry if (email.endsWith("@faircode.eu")) { long expiry = Long.parseLong(email.split("\\.")[0]); long time = System.currentTimeMillis() / 1000L; if (time > expiry) { Util.log(null, Log.WARN, "Licensing: expired"); return null; } } // Valid return new String[] { name, email, signature }; } } catch (FileNotFoundException ex) { return null; } catch (Throwable ex) { bug(null, ex); return null; } } else Util.log(null, Log.INFO, "Licensing: no license file"); return null; }