System directories
| Method | Result |
|---|---|
| Environment.getDataDirectory() | /data |
| Environment.getDownloadCacheDirectory() | /cache |
| Environment.getRootDirectory() | /system |
External storage directories
| public void loadFiles(){ | |
| new Thread( | |
| new Runnable() { | |
| @Override | |
| public void run() { | |
| final Activity activity = getActivity(); | |
| if(activity != null && isAdded()){ | |
| activity.runOnUiThread(new Runnable() { | |
| @Override | |
| public void run() { |
| package com.example.fconfig; | |
| import android.os.Bundle; | |
| import android.support.annotation.NonNull; | |
| import android.support.v7.app.AppCompatActivity; | |
| import android.util.Log; | |
| import android.view.View; | |
| import android.widget.TextView; | |
| import com.google.android.gms.tasks.OnCompleteListener; |
| import android.graphics.Rect; | |
| import android.support.v7.widget.GridLayoutManager; | |
| import android.support.v7.widget.RecyclerView; | |
| import android.view.View; | |
| public class EqualSpacingItemDecoration extends RecyclerView.ItemDecoration { | |
| private final int spacing; | |
| private int displayMode; | |
| public static final int HORIZONTAL = 0; |
| String sdCardPath = null; | |
| if (storageState.equals(Environment.MEDIA_MOUNTED)) { | |
| sdCardPath = Environment.getExternalStorageDirectory().getAbsolutePath(); | |
| } else { | |
| List<String> possiblePaths = new ArrayList<String>(); | |
| possiblePaths.add("/storage/sdcard1 "); //!< Motorola Xoom | |
| possiblePaths.add("/storage/extsdcard "); //!< Samsung SGS3 | |
| possiblePaths.add("/storage/sdcard0/external_sdcard"); // user request | |
| possiblePaths.add("/mnt/extsdcard"); |
| private String getSdcardFolder() { | |
| File externalStorage = Environment.getExternalStorageDirectory(); | |
| if (externalStorage.exists() && externalStorage.canWrite()) { | |
| File trySubDir1 = new File(externalStorage, "external_sd"); | |
| File trySubDir2 = new File(externalStorage, "sd"); | |
| if (trySubDir1.exists() && trySubDir1.canWrite()) { | |
| return trySubDir1.getAbsolutePath(); | |
| } else if (trySubDir2.exists() && trySubDir2.canWrite()) { | |
| return trySubDir2.getAbsolutePath(); | |
| } else { |
System directories
| Method | Result |
|---|---|
| Environment.getDataDirectory() | /data |
| Environment.getDownloadCacheDirectory() | /cache |
| Environment.getRootDirectory() | /system |
External storage directories
| public static String getExternalSdCardPath() { | |
| String path = null; | |
| File sdCardFile = null; | |
| List<String> sdCardPossiblePath = Arrays.asList("external_sd", "ext_sd", "external", "extSdCard"); | |
| for (String sdPath : sdCardPossiblePath) { | |
| File file = new File("/mnt/", sdPath); | |
| if (file.isDirectory() && file.canWrite()) { |
| @SuppressLint("SourceLockedOrientationActivity") | |
| public static void chequeaVersion(Activity activity){ | |
| //Verifica si es diferente de android O | |
| if (android.os.Build.VERSION.SDK_INT != Build.VERSION_CODES.O){ | |
| activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); | |
| Log.d("TAG", "No es android O"); | |
| }else{ | |
| activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); | |
| Log.d("TAG", "Es android O"); | |
| } |
| // Extension on intent | |
| fun Intent?.getFilePath(context: Context): String { | |
| return this?.data?.let { data -> RealPathUtil.getRealPath(context, data) ?: "" } ?: "" | |
| } | |
| fun Uri?.getFilePath(context: Context): String { | |
| return this?.let { uri -> RealPathUtil.getRealPath(context, uri) ?: "" } ?: "" | |
| } |
| public static String[] getStorageDirectories() { | |
| final Pattern DIR_SEPARATOR = Pattern.compile("/"); | |
| // Final set of paths | |
| final Set<String> rv = new HashSet<String>(); | |
| // Primary physical SD-CARD (not emulated) | |
| final String rawExternalStorage = System.getenv("EXTERNAL_STORAGE"); | |
| // All Secondary SD-CARDs (all exclude primary) separated by ":" | |
| final String rawSecondaryStoragesStr = System.getenv("SECONDARY_STORAGE"); | |
| // Primary emulated SD-CARD |