In the development and application of the process, often encounter problems need to acquire equipment storage path. Acquired from a lot to find on the internet are built-in storage location, not external SD card path, so I recommend using reflection mechanism to get the path of external storage.
Typically, Environment.getExternalStorageDirectory () Get the path is built-in memory; other methods as follows (due to different equipment manufacturers may be modified so that different devices may vary, several methods are provided below for reference):
[since the following methods are generally not visible, it is necessary to call by reflection]
Description:
1, the path can be acquired, if the external memory card exists, the path is shown as specific / storage / 3035-3633; if not, the display / storage / sdcard0 (what is specific, controlled by the underlying)
2, by the found, it determines whether or not the path is available; requiring getExternalStoragePathState () to determine whether the acquired status is available, the file or create () determines whether there is a file.exists.
Plagued by long-standing problem has finally been solved!
NOTE: use on reflection, the following main steps:
(1) Class mClass = Class.forName ( "android.os.Environment"); // load the class <?>
(2) Method, Method mClass.getMethod = ( "getInternalStoragePath", null); // second parameter: a parameter indicating the called method, the current method does not require parameters, and therefore null.
iF (method.isAccessible ()!) {// detection method is accessible.
method.setAccessible (to true);
}
(3) method.invoke (null, null); // first parameter: the parameter of the method requires: a second example of a method invocation parameter.