List of usage examples for android.os Environment getExternalStorageDirectory
public static File getExternalStorageDirectory()
From source file:Main.java
/** * Reads in model 83 points and returns a double array float containing the * coordinates x & y.// w w w.j av a2 s . c o m */ public static float[][] readBinModel83Pt2DFloat(String dir, String fileName) { float[][] array2D = new float[83][2]; float x; int i = 0; File sdLien = Environment.getExternalStorageDirectory(); File inFile = new File(sdLien + File.separator + dir + File.separator + fileName); Log.d(TAG, "path of file : " + inFile); if (!inFile.exists()) { throw new RuntimeException("File doesn't exist"); } DataInputStream in = null; try { in = new DataInputStream(new FileInputStream(inFile)); } catch (FileNotFoundException e) { e.printStackTrace(); } try { while (true) { x = in.readFloat(); array2D[i][0] = x; x = in.readFloat(); array2D[i][1] = x; i++; } } catch (EOFException e) { try { Log.d(TAG, "close"); in.close(); } catch (IOException e1) { e1.printStackTrace(); } } catch (IOException e) { e.printStackTrace(); } finally { if (in != null) { try { //free ressources Log.d(TAG, "close"); in.close(); } catch (IOException e) { e.printStackTrace(); } } } return array2D; }
From source file:Main.java
/** * Get the external storage path of the device * * @return The external storage path of the device. *///w ww . j a v a 2s . c om public static String getAppRootDirectory() { try { if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { return null; } } catch (Exception e) { // Catch exception is trying to fix a crash inside of Environment.getExternalStorageState(). e.printStackTrace(); return null; } String rootDir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + ROOT_DIR + "/"; File file = new File(rootDir); if (!file.exists()) { if (!file.mkdirs()) { return null; } } return rootDir; }
From source file:Main.java
static String GenerateFilename() { String logfile = Environment.getExternalStorageDirectory().getPath() + "/screenstandby" + getDateTime() + ".backup-ss"; return logfile; }
From source file:Main.java
/** * ********************************************************************************************** * Returns size in MegaBytes./* w w w .j a va2 s.co m*/ * * @author Dan * <p/> * If you need calculate external memory, change this: StatFs statFs * = new StatFs(Environment.getRootDirectory().getAbsolutePath()); * to this: StatFs statFs = new * StatFs(Environment.getExternalStorageDirectory * ().getAbsolutePath()); * ************************************************************************************************ */ public static long TotalMemory() { StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath()); long Total = (statFs.getBlockCountLong() * statFs.getBlockSize()) / 1048576; return Total; }
From source file:Main.java
private static File createMediaFile(Context context, String parentPath) { String state = Environment.getExternalStorageState(); File rootDir = state.equals(Environment.MEDIA_MOUNTED) ? Environment.getExternalStorageDirectory() : context.getCacheDir();/* ww w . j a v a 2s.c om*/ File folderDir = new File(rootDir.getAbsolutePath() + parentPath); if (!folderDir.exists() && folderDir.mkdirs()) { } String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.CHINA).format(new Date()); String fileName = APP_NAME + "_" + timeStamp + ""; File tmpFile = new File(folderDir, fileName + POSTFIX); return tmpFile; }
From source file:Main.java
/** * Read the featureVector_Shape.dat file. * Build the double array and return it. * k : number of rows//from w ww . j av a 2s.co m * n : number of columns */ public static float[][] readBinFloatDoubleArray(String dir, String fileName, int k, int n) { float[][] array2D = new float[k][n]; float x; File sdLien = Environment.getExternalStorageDirectory(); File inFile = new File(sdLien + File.separator + dir + File.separator + fileName); Log.d(TAG, "path of file : " + inFile); if (!inFile.exists()) { throw new RuntimeException("File doesn't exist"); } DataInputStream in = null; try { in = new DataInputStream(new FileInputStream(inFile)); } catch (FileNotFoundException e) { e.printStackTrace(); } try { for (int i = 0; i < k; i++) { for (int j = 0; j < n; j++) { x = in.readFloat(); array2D[i][j] = x; } } } catch (EOFException e) { try { Log.d(TAG, "close"); in.close(); } catch (IOException e1) { e1.printStackTrace(); } } catch (IOException e) { e.printStackTrace(); } finally { if (in != null) { try { //free ressources Log.d(TAG, "close"); in.close(); } catch (IOException e) { e.printStackTrace(); } } } return array2D; }
From source file:Main.java
public static String getBaseFilePath() { String path = Environment.getExternalStorageDirectory() + "/wholewriter/"; System.out.println("getBaseFilePath-------------" + path); return path;//w ww .j a va 2 s. com }
From source file:Main.java
public static Intent getImageFromGalleryCamera(Context context) { // Determine Uri of camera image to save. File root = new File( Environment.getExternalStorageDirectory() + File.separator + "dianta/camera" + File.separator); root.mkdirs();//from w w w. jav a 2 s .co m String fname = "dianta-" + System.currentTimeMillis() + ".jpg"; File sdImageMainDirectory = new File(root, fname); Uri outputFileUri = Uri.fromFile(sdImageMainDirectory); // camera List<Intent> cameraIntents = new ArrayList<>(); Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); PackageManager lPackageManager = context.getPackageManager(); List<ResolveInfo> listCam = lPackageManager.queryIntentActivities(captureIntent, 0); for (ResolveInfo rInfo : listCam) { String packageName = rInfo.activityInfo.packageName; Intent lIntent = new Intent(captureIntent); lIntent.setComponent(new ComponentName(rInfo.activityInfo.packageName, rInfo.activityInfo.name)); lIntent.setPackage(packageName); //save camera result to external storage lIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); cameraIntents.add(lIntent); } //ugly hacks for camera helper lastCameraImageSaved = outputFileUri; // gallery Intent galleryIntent = new Intent(); galleryIntent.setType("image/*"); galleryIntent.setAction(Intent.ACTION_PICK); Intent chooserIntent = Intent.createChooser(galleryIntent, "Pilih Sumber"); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[cameraIntents.size()])); return chooserIntent; }
From source file:Main.java
/** * Create a File for saving an image in the * "/Android/data/package.name/Files" directory * * @param context application context//ww w . java 2s. c om * @return a new File for saving an image */ private static File getOutputMediaFile(Context context) { // To be safe, you should check that the SDCard is mounted // using Environment.getExternalStorageState() before doing this. File mediaStorageDir = new File( Environment.getExternalStorageDirectory() + "/Android/data/" + context.getPackageName() + "/Files"); // This location works best if you want the created images to be shared // between applications and persist after your app has been uninstalled. // Create the storage directory if it does not exist if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { return null; } } // Create a media file name String timeStamp = new SimpleDateFormat("ddMMyyyy_HHmmssSS", Locale.ENGLISH).format(new Date()); File mediaFile; String mImageName = "FRIDGE_" + timeStamp + ".jpg"; mediaFile = new File(mediaStorageDir.getPath() + File.separator + mImageName); return mediaFile; }
From source file:Main.java
public static File getExternalFile(String file) { return new File(Environment.getExternalStorageDirectory(), file); }