List of usage examples for android.os Environment isExternalStorageEmulated
public static boolean isExternalStorageEmulated()
From source file:Main.java
public static File getDir() { String rootDir = ""; if (Environment.isExternalStorageEmulated()) { rootDir = Environment.getExternalStorageDirectory().toString() + "/" + Environment.DIRECTORY_DCIM; } else {//w w w . ja v a 2 s .com rootDir = Environment.getDataDirectory().toString() + "/" + Environment.DIRECTORY_DCIM; } File imageDirectory = new File(rootDir); if (!imageDirectory.exists()) { imageDirectory.mkdirs(); } return imageDirectory; }
From source file:Main.java
@SuppressLint("NewApi") @SuppressWarnings("rawtypes") public static boolean isExtStorageEmulated() { if (Build.VERSION.SDK_INT >= 11) { return Environment.isExternalStorageEmulated(); }/*from w w w . jav a2 s. co m*/ return false; }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) public static File getDiskCacheDir(Context context, String uniqueName) { String cachePath;/*from w w w .j a va 2 s .com*/ if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageEmulated()) { cachePath = context.getExternalCacheDir().getPath(); } else { cachePath = context.getCacheDir().getPath(); } return new File(cachePath + File.separator + uniqueName); }
From source file:eu.mhutti1.utils.storage.StorageDeviceUtils.java
public static ArrayList<StorageDevice> getStorageDevices(Context context, boolean writable) { mStorageDevices = new ArrayList<>(); // Add as many possible mount points as we know about // Only add this device if its very likely that we have missed a users sd card if (Environment.isExternalStorageEmulated()) { // This is our internal storage directory mStorageDevices.add(new StorageDevice( generalisePath(Environment.getExternalStorageDirectory().getPath(), writable), true)); } else {//w ww. j a v a 2 s . co m // This is the internal directory of our app that only we can write to mStorageDevices.add(new StorageDevice(context.getFilesDir().getPath(), true)); // This is an external storage directory mStorageDevices.add(new StorageDevice( generalisePath(Environment.getExternalStorageDirectory().getPath(), writable), false)); } // These are possible manufacturer sdcard mount points String[] paths = ExternalPaths.getPossiblePaths(); for (String path : paths) { if (path.endsWith("*")) { File root = new File(path.substring(0, path.length() - 1)); File[] directories = root.listFiles(new FileFilter() { @Override public boolean accept(File file) { return file.isDirectory(); } }); if (directories != null) { for (File dir : directories) { mStorageDevices.add(new StorageDevice(dir, false)); } } } else { mStorageDevices.add(new StorageDevice(path, false)); } } // Iterate through any sdcards manufacturers may have specified in Kitkat+ and add them if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { for (File file : context.getExternalFilesDirs("")) { if (file != null) { mStorageDevices.add(new StorageDevice(generalisePath(file.getPath(), writable), false)); } } } // Check all devices exist, we can write to them if required and they are not duplicates return checkStorageValid(writable); }
From source file:com.fallahpoor.infocenter.fragments.StorageFragment.java
private String getExternalStoragePath() { if (!Environment.isExternalStorageEmulated() && Environment.getExternalStorageState().equalsIgnoreCase(Environment.MEDIA_MOUNTED)) { return Environment.getExternalStorageDirectory().getAbsolutePath(); } else {/*from w w w . jav a 2 s.co m*/ return System.getenv("SECONDARY_STORAGE"); } }
From source file:com.android.settings.applications.CanBeOnSdCardChecker.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true);/* w w w. ja v a 2 s. c o m*/ mApplicationsState = ApplicationsState.getInstance(getActivity().getApplication()); Intent intent = getActivity().getIntent(); String action = intent.getAction(); int defaultListType = LIST_TYPE_DOWNLOADED; String className = getArguments() != null ? getArguments().getString("classname") : null; if (className == null) { className = intent.getComponent().getClassName(); } if (className.equals(RunningServicesActivity.class.getName()) || className.endsWith(".RunningServices")) { defaultListType = LIST_TYPE_RUNNING; } else if (className.equals(StorageUseActivity.class.getName()) || Intent.ACTION_MANAGE_PACKAGE_STORAGE.equals(action) || className.endsWith(".StorageUse")) { mSortOrder = SORT_ORDER_SIZE; defaultListType = LIST_TYPE_ALL; } else if (Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS.equals(action)) { // Select the all-apps list, with the default sorting defaultListType = LIST_TYPE_ALL; } if (savedInstanceState != null) { mSortOrder = savedInstanceState.getInt(EXTRA_SORT_ORDER, mSortOrder); int tmp = savedInstanceState.getInt(EXTRA_DEFAULT_LIST_TYPE, -1); if (tmp != -1) defaultListType = tmp; mShowBackground = savedInstanceState.getBoolean(EXTRA_SHOW_BACKGROUND, false); } mDefaultListType = defaultListType; final Intent containerIntent = new Intent().setComponent(StorageMeasurement.DEFAULT_CONTAINER_COMPONENT); getActivity().bindService(containerIntent, mContainerConnection, Context.BIND_AUTO_CREATE); mInvalidSizeStr = getActivity().getText(R.string.invalid_size_value); mComputingSizeStr = getActivity().getText(R.string.computing_size); TabInfo tab = new TabInfo(this, mApplicationsState, getActivity().getString(R.string.filter_apps_third_party), LIST_TYPE_DOWNLOADED, this, savedInstanceState); mTabs.add(tab); if (!Environment.isExternalStorageEmulated()) { tab = new TabInfo(this, mApplicationsState, getActivity().getString(R.string.filter_apps_onsdcard), LIST_TYPE_SDCARD, this, savedInstanceState); mTabs.add(tab); } tab = new TabInfo(this, mApplicationsState, getActivity().getString(R.string.filter_apps_running), LIST_TYPE_RUNNING, this, savedInstanceState); mTabs.add(tab); tab = new TabInfo(this, mApplicationsState, getActivity().getString(R.string.filter_apps_all), LIST_TYPE_ALL, this, savedInstanceState); mTabs.add(tab); tab = new TabInfo(this, mApplicationsState, getActivity().getString(R.string.filter_apps_disabled), LIST_TYPE_DISABLED, this, savedInstanceState); mTabs.add(tab); mNumTabs = mTabs.size(); }
From source file:com.android.server.MountService.java
@VisibleForTesting public static String buildObbPath(final String canonicalPath, int userId, boolean forVold) { // TODO: allow caller to provide Environment for full testing // TODO: extend to support OBB mounts on secondary external storage // Only adjust paths when storage is emulated if (!Environment.isExternalStorageEmulated()) { return canonicalPath; }/*from ww w.j a va 2s .c om*/ String path = canonicalPath.toString(); // First trim off any external storage prefix final UserEnvironment userEnv = new UserEnvironment(userId); // /storage/emulated/0 final String externalPath = userEnv.getExternalStorageDirectory().getAbsolutePath(); // /storage/emulated_legacy final String legacyExternalPath = Environment.getLegacyExternalStorageDirectory().getAbsolutePath(); if (path.startsWith(externalPath)) { path = path.substring(externalPath.length() + 1); } else if (path.startsWith(legacyExternalPath)) { path = path.substring(legacyExternalPath.length() + 1); } else { return canonicalPath; } // Handle special OBB paths on emulated storage final String obbPath = "Android/obb"; if (path.startsWith(obbPath)) { path = path.substring(obbPath.length() + 1); if (forVold) { return new File(Environment.getEmulatedStorageObbSource(), path).getAbsolutePath(); } else { final UserEnvironment ownerEnv = new UserEnvironment(UserHandle.USER_OWNER); return new File(ownerEnv.buildExternalStorageAndroidObbDirs()[0], path).getAbsolutePath(); } } // Handle normal external storage paths if (forVold) { return new File(Environment.getEmulatedStorageSource(userId), path).getAbsolutePath(); } else { return new File(userEnv.getExternalDirsForApp()[0], path).getAbsolutePath(); } }