Java Code Examples for android.os.Environment#getRootDirectory()
The following examples show how to use
android.os.Environment#getRootDirectory() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: FireFiles File: ExternalStorageProvider.java License: Apache License 2.0 | 6 votes |
@Override public Cursor queryRoots(String[] projection) throws FileNotFoundException { final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection)); synchronized (mRootsLock) { for (RootInfo root : mRoots.values()) { final RowBuilder row = result.newRow(); row.add(Root.COLUMN_ROOT_ID, root.rootId); row.add(Root.COLUMN_FLAGS, root.flags); row.add(Root.COLUMN_TITLE, root.title); row.add(Root.COLUMN_DOCUMENT_ID, root.docId); row.add(Root.COLUMN_PATH, root.path); if(ROOT_ID_PRIMARY_EMULATED.equals(root.rootId) || root.rootId.startsWith(ROOT_ID_SECONDARY) || root.rootId.startsWith(ROOT_ID_PHONE)) { final File file = root.rootId.startsWith(ROOT_ID_PHONE) ? Environment.getRootDirectory() : root.path; row.add(Root.COLUMN_AVAILABLE_BYTES, file.getFreeSpace()); row.add(Root.COLUMN_CAPACITY_BYTES, file.getTotalSpace()); } } } return result; }
Example 2
Source Project: FireFiles File: ExternalStorageProvider.java License: Apache License 2.0 | 6 votes |
@Override public Cursor queryRoots(String[] projection) throws FileNotFoundException { final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection)); synchronized (mRootsLock) { for (RootInfo root : mRoots.values()) { final RowBuilder row = result.newRow(); row.add(Root.COLUMN_ROOT_ID, root.rootId); row.add(Root.COLUMN_FLAGS, root.flags); row.add(Root.COLUMN_TITLE, root.title); row.add(Root.COLUMN_DOCUMENT_ID, root.docId); row.add(Root.COLUMN_PATH, root.path); if(ROOT_ID_PRIMARY_EMULATED.equals(root.rootId) || root.rootId.startsWith(ROOT_ID_SECONDARY) || root.rootId.startsWith(ROOT_ID_PHONE)) { final File file = root.rootId.startsWith(ROOT_ID_PHONE) ? Environment.getRootDirectory() : root.path; row.add(Root.COLUMN_AVAILABLE_BYTES, file.getFreeSpace()); row.add(Root.COLUMN_CAPACITY_BYTES, file.getTotalSpace()); } } } return result; }
Example 3
Source Project: FireFiles File: ExternalStorageProvider.java License: Apache License 2.0 | 6 votes |
@Override public Cursor queryRoots(String[] projection) throws FileNotFoundException { final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection)); synchronized (mRootsLock) { for (RootInfo root : mRoots.values()) { final RowBuilder row = result.newRow(); row.add(Root.COLUMN_ROOT_ID, root.rootId); row.add(Root.COLUMN_FLAGS, root.flags); row.add(Root.COLUMN_TITLE, root.title); row.add(Root.COLUMN_DOCUMENT_ID, root.docId); row.add(Root.COLUMN_PATH, root.path); if(ROOT_ID_PRIMARY_EMULATED.equals(root.rootId) || root.rootId.startsWith(ROOT_ID_SECONDARY) || root.rootId.startsWith(ROOT_ID_PHONE)) { final File file = root.rootId.startsWith(ROOT_ID_PHONE) ? Environment.getRootDirectory() : root.path; row.add(Root.COLUMN_AVAILABLE_BYTES, file.getFreeSpace()); row.add(Root.COLUMN_CAPACITY_BYTES, file.getTotalSpace()); } } } return result; }
Example 4
Source Project: IPTVFree File: FileSelector.java License: Apache License 2.0 | 6 votes |
public FileSelector(final Context context, final FileOperation operation, final OnHandleFileListener onHandleFileListener, final String[] fileFilters) { mContext = context; mOnHandleFileListener = onHandleFileListener; final File sdCard = Environment.getExternalStorageDirectory(); if (sdCard.canRead()) { mCurrentLocation = sdCard; } else { mCurrentLocation = Environment.getRootDirectory(); } mDialog = new Dialog(context); mDialog.setContentView(R.layout.dialog); mDialog.setTitle(mCurrentLocation.getAbsolutePath()); prepareFilterSpinner(fileFilters); prepareFilesList(); setSaveLoadButton(operation); setNewFolderButton(operation); setCancelButton(); }
Example 5
Source Project: applivery-android-sdk File: AndroidDeviceDetailsInfo.java License: Apache License 2.0 | 6 votes |
@Override public String getFreeDiskPercentage() { File rootDirectory = Environment.getRootDirectory(); StatFs fileSystemData = new StatFs(rootDirectory.getPath()); long blockSize; long totalSize; long availableSize; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { blockSize = fileSystemData.getBlockSizeLong(); totalSize = fileSystemData.getBlockCountLong() * blockSize; availableSize = fileSystemData.getAvailableBlocksLong() * blockSize; } else { blockSize = fileSystemData.getBlockSize(); totalSize = fileSystemData.getBlockCount() * blockSize; availableSize = fileSystemData.getAvailableBlocks() * blockSize; } long freeDiskPercentage = availableSize * 100 / totalSize; return String.valueOf(freeDiskPercentage); }
Example 6
Source Project: ToGoZip File: SettingsImpl.java License: GNU General Public License v3.0 | 6 votes |
/** * calculates the dafault-path value for 2go.zip */ public static String getDefaultZipDirPath(Context context) { File rootDir = null; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { // before api-14/android-4.4/KITKAT // write support on sdcard, if mounted Boolean isSDPresent = Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED); rootDir = ((isSDPresent)) ? Environment.getExternalStorageDirectory() : Environment.getRootDirectory(); } else if (Global.USE_DOCUMENT_PROVIDER && (zipDocDirUri != null)) { // DocumentFile docDir = DocumentFile.fromTreeUri(context, Uri.parse(zipDocDirUri)); DocumentFile docDir = DocumentFile.fromFile(new File(zipDocDirUri)); if ((docDir != null) && docDir.canWrite()) { return rootDir.getAbsolutePath(); } } if (rootDir == null) { // since android 4.4 Environment.getDataDirectory() and .getDownloadCacheDirectory () // is protected by android-os :-( rootDir = getRootDir44(); } final String zipfile = rootDir.getAbsolutePath() + "/copy"; return zipfile; }
Example 7
Source Project: NotchAdaptedTest File: RomUtils.java License: Apache License 2.0 | 5 votes |
private static String getSystemPropertyByStream(final String key) { try { Properties prop = new Properties(); FileInputStream is = new FileInputStream( new File(Environment.getRootDirectory(), "build.prop") ); prop.load(is); return prop.getProperty(key, ""); } catch (Exception ignore) { /**/ } return ""; }
Example 8
Source Project: XAPKInstaller File: RomUtils.java License: Apache License 2.0 | 5 votes |
private static String getSystemPropertyByStream(final String key) { try { Properties prop = new Properties(); FileInputStream is = new FileInputStream( new File(Environment.getRootDirectory(), "build.prop") ); prop.load(is); return prop.getProperty(key, ""); } catch (Exception ignore) { /**/ } return ""; }
Example 9
Source Project: DevUtils File: ROMUtils.java License: Apache License 2.0 | 5 votes |
/** * 获取 system prop 文件指定属性信息 * @param key 属性 key * @return system prop 文件指定属性信息 */ private static String getSystemPropertyByStream(final String key) { try { Properties prop = new Properties(); FileInputStream is = new FileInputStream( new File(Environment.getRootDirectory(), "build.prop") ); prop.load(is); return prop.getProperty(key, ""); } catch (Throwable ignore) { } return ""; }
Example 10
Source Project: Common File: RomUtils.java License: Apache License 2.0 | 5 votes |
private static String getSystemPropertyByStream(final String key) { try { Properties prop = new Properties(); FileInputStream is = new FileInputStream( new File(Environment.getRootDirectory(), "build.prop") ); prop.load(is); return prop.getProperty(key, ""); } catch (Exception ignore) {/**/} return ""; }
Example 11
Source Project: AndroidUtilCode File: RomUtils.java License: Apache License 2.0 | 5 votes |
private static String getSystemPropertyByStream(final String key) { try { Properties prop = new Properties(); FileInputStream is = new FileInputStream( new File(Environment.getRootDirectory(), "build.prop") ); prop.load(is); return prop.getProperty(key, ""); } catch (Exception ignore) {/**/} return ""; }
Example 12
Source Project: FileManager File: DiskStat.java License: Apache License 2.0 | 5 votes |
private void calculateInternalSpace() { File root = Environment.getRootDirectory(); StatFs sf = new StatFs(root.getPath()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { mInternalBlockSize = sf.getBlockSizeLong(); mInternalBlockCount = sf.getBlockCountLong(); mInternalAvailableBlocks = sf.getAvailableBlocksLong(); } else { mInternalBlockSize = sf.getBlockSize(); mInternalBlockCount = sf.getBlockCount(); mInternalAvailableBlocks = sf.getAvailableBlocks(); } }
Example 13
Source Project: CleanExpert File: DiskStat.java License: MIT License | 5 votes |
private void calculateInternalSpace() { File root = Environment.getRootDirectory(); StatFs sf = new StatFs(root.getPath()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { mInternalBlockSize = sf.getBlockSizeLong(); mInternalBlockCount = sf.getBlockCountLong(); mInternalAvailableBlocks = sf.getAvailableBlocksLong(); } else { mInternalBlockSize = sf.getBlockSize(); mInternalBlockCount = sf.getBlockCount(); mInternalAvailableBlocks = sf.getAvailableBlocks(); } }
Example 14
Source Project: batteryhub File: Storage.java License: Apache License 2.0 | 5 votes |
/** * Storage details for internal, external, secondary and system partitions. * External and secondary storage details are not exactly reliable. * * @return Thrift-compatible StorageDetails object */ public static StorageDetails getStorageDetails() { StorageDetails sd = new StorageDetails(); // Internal File path = Environment.getDataDirectory(); long[] internal = getStorageDetailsForPath(path); if (internal.length == 2) { sd.free = (int) internal[0]; sd.total = (int) internal[1]; } // External long[] external = getExternalStorageDetails(); if (external.length == 2) { sd.freeExternal = (int) external[0]; sd.totalExternal = (int) external[1]; } // Secondary long[] secondary = getSecondaryStorageDetails(); if (secondary.length == 2) { sd.freeSecondary = (int) secondary[0]; sd.totalSecondary = (int) secondary[1]; } // System path = Environment.getRootDirectory(); long[] system = getStorageDetailsForPath(path); if (system.length == 2) { sd.freeSystem = (int) system[0]; sd.totalSystem = (int) system[1]; } return sd; }
Example 15
Source Project: Fishing File: CommonModel.java License: GNU General Public License v3.0 | 5 votes |
private String findDownLoadDirectory(){ if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){ JUtils.Log("找到SD卡"); return Environment.getExternalStorageDirectory() + "/" + "download/"; }else{ JUtils.Log("没有SD卡"); return Environment.getRootDirectory() + "/" + "download/"; } }
Example 16
Source Project: prettygoodmusicplayer File: Utils.java License: GNU General Public License v3.0 | 5 votes |
/** * Gets the root storage directory of this device. * @return */ static File getRootStorageDirectory() { File ext = Environment.getExternalStorageDirectory(); if(ext == null){ ext = Environment.getRootDirectory(); return ext; } File parent = ext.getParentFile(); if (parent != null) { return parent; } return ext; }
Example 17
Source Project: deagle File: Miui.java License: Apache License 2.0 | 5 votes |
private static String getMiuiVerName() { final Properties prop = new Properties(); final File file = new File(Environment.getRootDirectory(), "build.prop"); try { prop.load(new FileInputStream(file)); } catch (final IOException e) { try { // Try again once more prop.load(new FileInputStream(file)); } catch (final IOException ex) { return ""; } } final String ver_name = prop.getProperty("ro.miui.ui.version.name"); return ver_name == null ? "" : ver_name; }
Example 18
Source Project: Libraries-for-Android-Developers File: FileHandle.java License: MIT License | 5 votes |
public FileHandle(){ if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { rootDir = Environment.getExternalStorageDirectory(); } else { rootDir = Environment.getRootDirectory(); } }
Example 19
Source Project: Kore File: LocalFileListFragment.java License: Apache License 2.0 | 4 votes |
@Override protected TabsAdapter createTabsAdapter(DataHolder dataHolder) { ListType.Sort sortMethod = new ListType.Sort(ListType.Sort.SORT_METHOD_PATH, true, true); Bundle dcimFileListArgs = new Bundle(); String dcim = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath(); dcimFileListArgs.putString(LocalMediaFileListFragment.ROOT_PATH_LOCATION, dcim); dcimFileListArgs.putParcelable(LocalMediaFileListFragment.SORT_METHOD, sortMethod); Bundle directoryMusicFileListArgs = new Bundle(); String directoryMusic = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC).getAbsolutePath(); directoryMusicFileListArgs.putString(LocalMediaFileListFragment.ROOT_PATH_LOCATION, directoryMusic); directoryMusicFileListArgs.putParcelable(LocalMediaFileListFragment.SORT_METHOD, sortMethod); Bundle directoryMoviesFileListArgs = new Bundle(); String directoryMovies = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).getAbsolutePath(); directoryMoviesFileListArgs.putString(LocalMediaFileListFragment.ROOT_PATH_LOCATION, directoryMovies); directoryMoviesFileListArgs.putParcelable(LocalMediaFileListFragment.SORT_METHOD, sortMethod); Bundle externalStorageFileListArgs = new Bundle(); String externalStorage = Environment.getExternalStorageDirectory().getAbsolutePath(); externalStorageFileListArgs.putString(LocalMediaFileListFragment.ROOT_PATH_LOCATION, externalStorage); externalStorageFileListArgs.putParcelable(LocalMediaFileListFragment.SORT_METHOD, sortMethod); TabsAdapter tabsAdapter = new TabsAdapter(getActivity(), getChildFragmentManager()) .addTab(LocalMediaFileListFragment.class, dcimFileListArgs, R.string.dcim, 1) .addTab(LocalMediaFileListFragment.class, directoryMusicFileListArgs, R.string.music, 2) .addTab(LocalMediaFileListFragment.class, directoryMoviesFileListArgs, R.string.movies, 3) .addTab(LocalMediaFileListFragment.class, externalStorageFileListArgs, R.string.external_storage, 4); Environment.getRootDirectory(); File[] externalFilesDirs = ContextCompat.getExternalFilesDirs(getActivity(),null); for (int i = 0; i < externalFilesDirs.length; i++) { File file = externalFilesDirs[i].getParentFile().getParentFile().getParentFile().getParentFile(); if (file.getAbsolutePath().equals(externalStorage)) continue; Bundle bundle = new Bundle(); bundle.putString(LocalMediaFileListFragment.ROOT_PATH_LOCATION, file.getAbsolutePath()); bundle.putParcelable(LocalMediaFileListFragment.SORT_METHOD, sortMethod); tabsAdapter.addTab(LocalMediaFileListFragment.class, bundle, file.getName(),i+2); } return tabsAdapter; }
Example 20
Source Project: DevUtils File: PathUtils.java License: Apache License 2.0 | 2 votes |
/** * 获取 Android 系统根目录 - path /system * @return /system */ public File getRootDirectory() { return Environment.getRootDirectory(); }