Я пытаюсь получить URI файла / папки, используя цикл, который находится внутри подпапки TreeUri dir.
Вот мой treeUri для пути / storage / 0018-E24D
content: //com.android.externalstorage.documents/tree/0018-E24D% 3A
Файл находится во вложенной папке treeUri и имеет путь / storage / 0018-E24D / apks / Входной депозит Slip-2019.pdf
Мой код ниже
public static Uri getPathUri(String path,Uri TreeUri,Context context) {
DocumentFile[] fileList=null;
List xSplit=null;
xSplit= Arrays.asList(path.split("/"));
DocumentFile file=DocumentFile.fromTreeUri(context,TreeUri);
fileList=file.listFiles();
for(DocumentFile df:fileList)
{
if(xSplit.contains(df.getName()))
{
if(df.getName().equals(new File(path).getName())){
return df.getUri();
}
else
{
return getPathUri(path,df.getUri(),context);
}
}
}
return null;
}
OnActivityShow
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("GotUri", FileUtil.getPathUri("/storage/0018-E24D/apks/Admission deposit Slip-2019.pdf",treeUri, this));
}
Но я не смог получить URI этого файла