System directories
Method | Result |
---|---|
Environment.getDataDirectory() | /data |
Environment.getDownloadCacheDirectory() | /cache |
Environment.getRootDirectory() | /system |
External storage directories
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 |
// 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 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()) { |
System directories
Method | Result |
---|---|
Environment.getDataDirectory() | /data |
Environment.getDownloadCacheDirectory() | /cache |
Environment.getRootDirectory() | /system |
External storage directories
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 { |
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"); |
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; |
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; |