0

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

nhCoder
  • 451
  • 5
  • 11
  • Dear Naveed, It will become easier to help if you can share the output of your current code. Or the details of errors/ warnings you get. – B-Abbasi Jan 01 '19 at 13:27
  • actually the method loops in storage/0018-E24D/apks/ directory and app doesn't responds – nhCoder Jan 01 '19 at 13:37

0 Answers0