List of usage examples for android.support.v4.content ContextCompat getExternalFilesDirs
public static File[] getExternalFilesDirs(Context context, String str)
From source file:com.networking.utils.Utils.java
public static String getRootDirPath(Context context) { if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { File file = ContextCompat.getExternalFilesDirs(context.getApplicationContext(), null)[0]; return file.getAbsolutePath(); } else {//ww w . jav a 2s.c o m return context.getApplicationContext().getFilesDir().getAbsolutePath(); } }
From source file:org.digitalcampus.oppia.utils.storage.ExternalStorageStrategy.java
public void updateStorageLocation(Context ctx) { //If no mount argument passed, we set the default external mount File[] dirs = ContextCompat.getExternalFilesDirs(ctx, null); if (dirs.length > 0) { String location = dirs[dirs.length - 1].toString(); updateLocationPreference(ctx, location); }/* ww w .ja v a 2 s . c o m*/ }
From source file:com.nadmm.airports.utils.SystemUtils.java
public static File getExternalDir(Context context, String dirName) { return ContextCompat.getExternalFilesDirs(context, dirName)[0]; }
From source file:org.isoron.uhabits.utils.FileUtils.java
@Nullable public static File getFilesDir(@Nullable String relativePath) { Context context = HabitsApplication.getContext(); File externalFilesDirs[] = ContextCompat.getExternalFilesDirs(context, null); if (externalFilesDirs == null) { Log.e("DatabaseHelper", "getFilesDir: getExternalFilesDirs returned null"); return null; }// w w w . ja v a 2 s . c om return getDir(externalFilesDirs, relativePath); }
From source file:org.gateshipone.odyssey.utils.FileExplorerHelper.java
/** * return the list of available storage volumes *///from www. ja v a2 s .co m public List<String> getStorageVolumes(Context context) { // create storage volume list ArrayList<String> storagePathList = new ArrayList<>(); File[] storageList = ContextCompat.getExternalFilesDirs(context, null); for (File storageFile : storageList) { if (null != storageFile) { storagePathList.add(storageFile.getAbsolutePath() .replaceAll("/Android/data/" + context.getPackageName() + "/files", "")); } } storagePathList.add("/"); return storagePathList; }
From source file:de.qspool.clementineremote.ui.settings.DefaultDirChooser.java
@TargetApi(Build.VERSION_CODES.KITKAT) private LinkedList<String> getDirectories() { LinkedList<String> directories = new LinkedList<>(); File[] defaultDirs = ContextCompat.getExternalFilesDirs(mContext, Environment.DIRECTORY_MUSIC); for (File f : defaultDirs) { if (f != null) directories.add(f.toString()); }/* w w w . j ava 2 s . co m*/ String publicMusicDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC) .toString(); if (canWriteToExternalStorage(publicMusicDir)) { directories.add(publicMusicDir); } if (canWriteToExternalStorage(Environment.getExternalStorageDirectory().getAbsolutePath())) { directories.add(mContext.getString(R.string.file_dialog_custom_paths_available)); } return directories; }
From source file:org.digitalcampus.oppia.utils.FileUtils.java
public static String getStorageLocationRoot(Context ctx) { File[] dirs = ContextCompat.getExternalFilesDirs(ctx, null); //get from prefs SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx); String location = prefs.getString(PrefsActivity.PREF_STORAGE_LOCATION, ""); // if location not set - then set it to first of dirs if (location.equals("") && dirs.length > 0) { location = dirs[dirs.length - 1].toString(); Editor editor = prefs.edit();//w ww . j a v a 2 s . c om editor.putString(PrefsActivity.PREF_STORAGE_LOCATION, location); editor.commit(); } return location; }
From source file:github.daneren2005.dsub.view.CacheLocationPreference.java
@Override protected void onBindDialogView(View view) { super.onBindDialogView(view); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { view.setLayoutParams(new ViewGroup.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT)); final EditText editText = (EditText) view.findViewById(android.R.id.edit); ViewGroup vg = (ViewGroup) editText.getParent(); LinearLayout cacheButtonsWrapper = (LinearLayout) LayoutInflater.from(context) .inflate(R.layout.cache_location_buttons, vg, true); Button internalLocation = (Button) cacheButtonsWrapper.findViewById(R.id.location_internal); Button externalLocation = (Button) cacheButtonsWrapper.findViewById(R.id.location_external); File[] dirs;/*from ww w . j a va2s.c om*/ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { dirs = context.getExternalMediaDirs(); } else { dirs = ContextCompat.getExternalFilesDirs(context, null); } // Past 5.0 we can query directly for SD Card File internalDir = null, externalDir = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { for (int i = 0; i < dirs.length; i++) { try { if (dirs[i] != null) { if (Environment.isExternalStorageRemovable(dirs[i])) { if (externalDir != null) { externalDir = dirs[i]; } } else { internalDir = dirs[i]; } if (internalDir != null && externalDir != null) { break; } } } catch (Exception e) { Log.e(TAG, "Failed to check if is external", e); } } } // Before 5.0, we have to guess. Most of the time the SD card is last if (externalDir == null) { for (int i = dirs.length - 1; i >= 0; i--) { if (dirs[i] != null) { externalDir = dirs[i]; break; } } } if (internalDir == null) { for (int i = 0; i < dirs.length; i++) { if (dirs[i] != null) { internalDir = dirs[i]; break; } } } final File finalInternalDir = new File(internalDir, "music"); final File finalExternalDir = new File(externalDir, "music"); final EditText editTextBox = (EditText) view.findViewById(android.R.id.edit); if (finalInternalDir != null && (finalInternalDir.exists() || finalInternalDir.mkdirs())) { internalLocation.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String path = finalInternalDir.getPath(); editTextBox.setText(path); } }); } else { internalLocation.setEnabled(false); } if (finalExternalDir != null && !finalInternalDir.equals(finalExternalDir) && (finalExternalDir.exists() || finalExternalDir.mkdirs())) { externalLocation.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String path = finalExternalDir.getPath(); editTextBox.setText(path); } }); } else { externalLocation.setEnabled(false); } } }
From source file:net.sf.fakenames.fddemo.BaseDirLayout.java
public void init() throws IOException { home = getBaseDir();/*from w w w .jav a2 s .c o m*/ mountInfo = MountsSingleton.get(os); final HashMap<File, String> pathNameMap = new HashMap<>(); File systemRoot = Environment.getRootDirectory(); try { systemRoot = systemRoot.getCanonicalFile(); } catch (IOException ignore) { // ok } pathNameMap.put(systemRoot, "Android system root"); File filesDir = getFilesDir(); try { filesDir = filesDir.getCanonicalFile(); } catch (IOException ignore) { // ok } pathNameMap.put(filesDir, "Internal private storage"); File[] external = ContextCompat.getExternalFilesDirs(this, null); for (int i = 0; i < external.length; ++i) { File resolved = external[i]; if (resolved == null) continue; try { resolved = resolved.getCanonicalFile(); } catch (IOException ignore) { // ok } pathNameMap.put(resolved, "External storage " + i); } List<StorageVolume> volumes = new ArrayList<>(); if (Build.VERSION.SDK_INT >= 24) { final StorageManager sm = (StorageManager) getSystemService(STORAGE_SERVICE); volumes.addAll(sm.getStorageVolumes()); } final Lock lock = mountInfo.getLock(); lock.lock(); try { parseMounts(pathNameMap, volumes); } finally { lock.unlock(); } }
From source file:org.wso2.emm.agent.api.DeviceState.java
public DeviceState(Context context) { this.context = context; this.info = new DeviceInfo(context); this.dataDirectory = new File(context.getFilesDir().getAbsoluteFile().toString()); if (externalMemoryAvailable()) { this.externalStorageDirectoryList = ContextCompat.getExternalFilesDirs(context, null); }//ww w . ja va2 s . c o m }