List of usage examples for android.support.v4.content ContextCompat getExternalFilesDirs
public static File[] getExternalFilesDirs(Context context, String str)
From source file:org.isoron.uhabits.helpers.DatabaseHelper.java
@Nullable public static File getFilesDir(@Nullable String relativePath) { Context context = HabitsApplication.getContext(); if (context == null) { Log.e("DatabaseHelper", "getFilesDir: no application context available"); return null; }/*from w w w .ja v a2 s . c om*/ File externalFilesDirs[] = ContextCompat.getExternalFilesDirs(context, null); if (externalFilesDirs == null) { Log.e("DatabaseHelper", "getFilesDir: getExternalFilesDirs returned null"); return null; } return getDir(externalFilesDirs, relativePath); }
From source file:com.orpheusdroid.screenrecorder.folderpicker.FolderChooser.java
private void initialize() { setPersistent(true);/* w w w . ja va 2 s . com*/ setDialogTitle(null); setDialogLayoutResource(R.layout.director_chooser); setPositiveButtonText(android.R.string.ok); setNegativeButtonText(android.R.string.cancel); currentDir = new File(Environment.getExternalStorageDirectory() + File.separator + Const.APPDIR); setSummary(getPersistedString(currentDir.getPath())); Log.d(Const.TAG, "Persisted String is: " + getPersistedString(currentDir.getPath())); File[] SDCards = ContextCompat.getExternalFilesDirs(getContext().getApplicationContext(), null); storages.add( new Storages(Environment.getExternalStorageDirectory().getPath(), Storages.StorageType.Internal)); prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); if (SDCards.length > 1) storages.add(new Storages(SDCards[1].getPath(), Storages.StorageType.External)); //getRemovableSDPath(SDCards[1]); }
From source file:org.dkf.jmule.util.SystemUtils.java
/** * Use this instead ContextCompat/*from w ww . j a v a2 s . c o m*/ * */ public static File[] getExternalFilesDirs(Context context) { if (hasKitKatOrNewer()) { List<File> dirs = new LinkedList<>(); for (File f : ContextCompat.getExternalFilesDirs(context, null)) { if (f != null) { dirs.add(f); } } return dirs.toArray(new File[dirs.size()]); } else { List<File> dirs = new LinkedList<>(); dirs.add(context.getExternalFilesDir(null)); try { String secondaryStorages = System.getenv("SECONDARY_STORAGE"); if (secondaryStorages != null) { String[] storages = secondaryStorages.split(File.pathSeparator); for (String s : storages) { dirs.add(new File(s)); } } } catch (Exception e) { LOG.error("Unable to get secondary external storages", e); } return dirs.toArray(new File[dirs.size()]); } }
From source file:com.bt.download.android.util.SystemUtils.java
/** * //w w w . jav a 2 s . c o m * Use this instead ContextCompat * * @param context * @return */ public static File[] getExternalFilesDirs(Context context) { if (hasKitKat()) { List<File> dirs = new LinkedList<File>(); for (File f : ContextCompat.getExternalFilesDirs(context, null)) { if (f != null) { dirs.add(f); } } return dirs.toArray(new File[0]); } else { List<File> dirs = new LinkedList<File>(); dirs.add(context.getExternalFilesDir(null)); try { String secondaryStorages = System.getenv("SECONDARY_STORAGE"); if (secondaryStorages != null) { String[] storages = secondaryStorages.split(File.pathSeparator); for (String s : storages) { dirs.add(new File(s)); } } } catch (Throwable e) { LOG.error("Unable to get secondary external storages", e); } return dirs.toArray(new File[0]); } }
From source file:org.alpine_toolkit.AlpineToolkitActivity.java
/**********************************************/ @Override/*from www .j a v a 2 s . c o m*/ public void onCreate(Bundle savedInstanceState) { Log.i(LOG_TAG, ">>>>>>>>>> AlpineToolkitActivity.onCreate <<<<<<<<<<"); // Fixme: hardcoded set_status_bar_background_color(Color.parseColor("#3949ab")); super.onCreate(savedInstanceState); Log.i(LOG_TAG, "Is service running? " + m_service_helper.is_service_running()); // Debug try { Process process = Runtime.getRuntime().exec("mount"); process.waitFor(); BufferedReader buffered_reader = new BufferedReader(new InputStreamReader(process.getInputStream())); StringBuilder output = new StringBuilder(); String line; while ((line = buffered_reader.readLine()) != null) output.append(line + "\n"); Log.i(LOG_TAG, "Mount: " + output); } // } catch (Exception e) { catch (java.io.IOException e) { } catch (java.lang.InterruptedException e) { } // Get external SDCard path Log.i(LOG_TAG, "External SDCard: " + Environment.getExternalStorageDirectory()); // /storage/emulated/0 // File[] paths = getExternalMediaDirs(); // API 21 File[] external_files_dirs = ContextCompat.getExternalFilesDirs(this, null); for (File path : external_files_dirs) Log.i(LOG_TAG, "external files dir: " + path); // Check permissions String[] permissions = { "android.permission.BODY_SENSORS", "android.permission.CAMERA", "android.permission.FLASHLIGHT", "android.permission.READ_EXTERNAL_STORAGE", "android.permission.READ_PHONE_STATE", "android.permission.WRITE_EXTERNAL_STORAGE", }; if (Build.VERSION.SDK_INT >= 21) { // Build.VERSION_CODES.LOLLIPOP for (String permission : permissions) { int rc = m_permission_helper.check_permission(permission); // if (rc == PermissionHelper.PermissionStatus.Granted.ordinal()) } } // get_display_metrics(); // get_device_id(); // set_torch_mode(true); }
From source file:org.rebo.app.MapLayers.java
public MapLayers() { mBackroundPlaceholder = new Layer(null) { };/*ww w . j av a2 s . co m*/ setBackgroundMap(-1); MAP_FOLDERS = ContextCompat.getExternalFilesDirs(App.activity, null); for (int i = 0; i < MAP_FOLDERS.length; i++) { File tmpFile = new File(MAP_FOLDERS[i], "maps/"); if (tmpFile.exists() || tmpFile.mkdirs()) { MAP_FOLDERS[i] = tmpFile; } else { MAP_FOLDERS[i] = null; } } MAP_FOLDERS = removeNullFile(MAP_FOLDERS); //Unzip downloaded Files: ArrayList<File> files = new ArrayList<>(); for (File f : MAP_FOLDERS) { files.addAll(FileUtils.walkExtension(f, ".ghz")); } for (File f : files) { App.activity.unzipAsync(f, App.activity); } }
From source file:com.sentaroh.android.SMBExplorer.FileIo.java
final public static boolean isAppSpecificDirectoryExists(Context c, String lmp) { boolean result = false; File[] fl = ContextCompat.getExternalFilesDirs(c, null); if (fl != null) {//Check App specific dir first for (int i = 0; i < fl.length; i++) { if (fl[i].getPath().startsWith(lmp)) { File lf = new File(fl[i].getPath() + "/temp.work"); if (lf.exists()) lf.delete();//from www . j a v a 2 s. co m try { if (lf.createNewFile()) { result = true; lf.delete(); } // Log.v("","path="+lf.getPath()); } catch (IOException e) { e.printStackTrace(); } break; } } } // Log.v("","result="+result+", lmp="+lmp); return result; }
From source file:org.goodev.droidddle.utils.IOUtil.java
public static File getBestAvailableFilesRoot(Context context) { File[] roots = ContextCompat.getExternalFilesDirs(context, null); if (roots != null) { for (File root : roots) { if (root == null) { continue; }//from w w w .ja v a 2s . c om if (Environment.MEDIA_MOUNTED.equals(EnvironmentCompat.getStorageState(root))) { return root; } } } // Worst case, resort to internal storage return context.getFilesDir(); }
From source file:uk.ac.ucl.excites.sapelli.shared.util.android.DeviceControl.java
/** * Returns absolute paths to application-specific directories on all external storage devices where the application can place persistent files it owns as in * {@link ContextCompat#getExternalFilesDirs(Context, String)}. This method also hard-codes the SD Card path for devices that are not supported in Android * i.e. Samsung Xcover 2//from www . ja v a2 s . co m * * @param context * @param type * @return */ public static File[] getExternalFilesDirs(Context context, String type) { // Get the paths ContextCompat File[] paths = ContextCompat.getExternalFilesDirs(context, type); String manufacturer = android.os.Build.MANUFACTURER; String model = android.os.Build.MODEL; // Check if Device is Samsung GT-S7710 (a.k.a. Samsung Galaxy Xcover 2) if (compare(manufacturer, "Samsung") && compare(model, "GT-S7710")) { // Hard code the path of the external SD Card paths = addPath(paths, getSdCardFilesDir(context, SAMSUNG_S7710_SD_PATH)); } return paths; }
From source file:org.chromium.ChromeSystemStorage.java
private File[] getExternalStorageDirectories() { return ContextCompat.getExternalFilesDirs(cordova.getActivity(), null); }