Java Code Examples for android.os.Environment#getRootDirectory()
The following examples show how to use
android.os.Environment#getRootDirectory() .
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 File: SettingsImpl.java From ToGoZip with 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 2
Source File: ExternalStorageProvider.java From FireFiles with 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 File: ExternalStorageProvider.java From FireFiles with 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 File: ExternalStorageProvider.java From FireFiles with 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 5
Source File: AndroidDeviceDetailsInfo.java From applivery-android-sdk with 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 File: FileSelector.java From IPTVFree with 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 7
Source File: DiskStat.java From CleanExpert with 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 8
Source File: FileHandle.java From Libraries-for-Android-Developers with MIT License | 5 votes |
public FileHandle(){ if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { rootDir = Environment.getExternalStorageDirectory(); } else { rootDir = Environment.getRootDirectory(); } }
Example 9
Source File: Miui.java From deagle with 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 10
Source File: Utils.java From prettygoodmusicplayer with 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 11
Source File: CommonModel.java From Fishing with 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 12
Source File: Storage.java From batteryhub with 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 13
Source File: RomUtils.java From NotchAdaptedTest with 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 14
Source File: DiskStat.java From FileManager with 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 15
Source File: RomUtils.java From AndroidUtilCode with 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 16
Source File: RomUtils.java From Common with 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 17
Source File: ROMUtils.java From DevUtils with 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 18
Source File: RomUtils.java From XAPKInstaller with 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 19
Source File: LocalFileListFragment.java From Kore with 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 File: PathUtils.java From DevUtils with Apache License 2.0 | 2 votes |
/** * 获取 Android 系统根目录 - path /system * @return /system */ public File getRootDirectory() { return Environment.getRootDirectory(); }