I m trying to get uri of file/folder using loop that is inside subfolder of TreeUri dir.
Here is my treeUri for Path /storage/0018-E24D
content://com.android.externalstorage.documents/tree/0018-E24D%3A
The file is inside the treeUri subfolder and has path /storage/0018-E24D/apks/Admission deposit Slip-2019.pdf
My Code Below
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));
}
But i m failed to get the uri of that file