Here is a written tool class that gets all the SD card paths by reflecting the system-hidden get all Mount Path method:
Package com.itheima.mobilesafe.utils;
import java.lang.reflect.InvocationTargetException;
import Java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import Android.content.Context;
import Android.os.storage.StorageManager;
Public class externalmemoryutils {
/**
* Gets all the external storage paths, returned as a collection
* @param context
* Context
* @return SD Card Path Collection
*/
Public Static List<string> getexternalmemorypaths (Context context) {
null;
StorageManager StorageManager = (StorageManager) context
. Getsystemservice (Context.storage_service);
Try {
Class<?>[] paramclasses = {};
Method Getvolumepathsmethod = StorageManager. class. GetMethod (
"getvolumepaths", paramclasses); //Returns a list of all installed volume paths
Getvolumepathsmethod.setaccessible (true);
Object[] params = {};
Object invoke = Getvolumepathsmethod.invoke (StorageManager, params);
New Arraylist<string> ();
for (int i = 0; I < (string[]) invoke). length; i++) {
String Path = ((string[)) invoke) [i];
List.add (path);
}
Catch (IllegalArgumentException e) {
E.printstacktrace ();
Catch (Nosuchmethodexception e) {
E.printstacktrace ();
Catch (Illegalaccessexception e) {
E.printstacktrace ();
Catch (InvocationTargetException e) {
E.printstacktrace ();
}
return list;
}
}