System.getenv(“模拟存储”目标)在Moto X Play(Android 6)上返回null

System.getenv(“模拟存储”目标)在Moto X Play(Android 6)上返回null,android,Android,我正在尝试使用此工具获取android应用程序中模拟存储的路径 System.getenv("EMULATED_STORAGE_TARGET") 到目前为止,除了Moto X play(Android 6.0)之外,这在所有设备上都能正常工作。在这种情况下,它返回null,即使存在模拟存储。路径应该是/storage/emulated/,但是System.getenv(“emulated\u storage\u TARGET”)返回null。我试图找到解决办法,但什么也没找到。谁能帮帮我吗。谢

我正在尝试使用此工具获取android应用程序中模拟存储的路径

System.getenv("EMULATED_STORAGE_TARGET")

到目前为止,除了Moto X play(Android 6.0)之外,这在所有设备上都能正常工作。在这种情况下,它返回
null
,即使存在模拟存储。路径应该是
/storage/emulated/
,但是
System.getenv(“emulated\u storage\u TARGET”)
返回
null
。我试图找到解决办法,但什么也没找到。谁能帮帮我吗。谢谢

因此,这里是我获得模拟存储目标的变通方法

List<String> paths = new ArrayList<>();
File[] files = context.getExternalFilesDirs(null);
for (File file : files) {
    String applicationSpecificAbsolutePath = file.getAbsolutePath();
    String emulatedRootPath = applicationSpecificAbsolutePath.substring(0, applicationSpecificAbsolutePath.indexOf("Android/data"));
    paths.add(emulatedRootPath);
}
//do what you want with the result paths
List path=new ArrayList();
File[]files=context.getExternalFilesDirs(null);
用于(文件:文件){
字符串applicationSpecificAbsolutePath=file.getAbsolutePath();
String emulatedRootPath=applicationSpecificAbsolutePath.substring(0,applicationSpecificAbsolutePath.indexOf(“Android/data”);
添加(emulatedRootPath);
}
//对结果路径执行所需操作

如果您有任何问题或建议,请让我知道

,因此,这里是我获得模拟存储目标的解决方法

List<String> paths = new ArrayList<>();
File[] files = context.getExternalFilesDirs(null);
for (File file : files) {
    String applicationSpecificAbsolutePath = file.getAbsolutePath();
    String emulatedRootPath = applicationSpecificAbsolutePath.substring(0, applicationSpecificAbsolutePath.indexOf("Android/data"));
    paths.add(emulatedRootPath);
}
//do what you want with the result paths
List path=new ArrayList();
File[]files=context.getExternalFilesDirs(null);
用于(文件:文件){
字符串applicationSpecificAbsolutePath=file.getAbsolutePath();
String emulatedRootPath=applicationSpecificAbsolutePath.substring(0,applicationSpecificAbsolutePath.indexOf(“Android/data”);
添加(emulatedRootPath);
}
//对结果路径执行所需操作

如果您有任何问题或建议,请告诉我

我对华硕Zenfone2,棉花糖6.0.1也有同样的问题。在这个问题上运气好吗?嘿,我发现这个命令根据制造商给出不同的结果。您必须使用不同的方法来解决问题,而不是使用上述命令。是的,我使用不同的方法来获得模拟的存储目标,但我不知道它是否经过优化。我将把我的解决方案发布在这里,安卓6中的外部存储发生了变化,同时还将提供获取这些路径的“简单”方法;您应该使用
上下文
类以与供应商无关的方式获取路径,而不是使用环境变量。此外,路径“应该”是供应商设置的任何路径!我在华硕Zenfone2,棉花糖6.0.1上也有同样的问题。在这个问题上运气好吗?嘿,我发现这个命令根据制造商给出不同的结果。您必须使用不同的方法来解决问题,而不是使用上述命令。是的,我使用不同的方法来获得模拟的存储目标,但我不知道它是否经过优化。我将把我的解决方案发布在这里,安卓6中的外部存储发生了变化,同时还将提供获取这些路径的“简单”方法;您应该使用
上下文
类以与供应商无关的方式获取路径,而不是使用环境变量。此外,路径“应该”是供应商设置的任何路径!