I am using an intent ACTION_OPEN_DOCUMENT_TREE which in activity results gives a path to folder. But that path is not correct to search file from specified folder.
Context: I am building an app that allows user to select directory where program will search for the file type but the path received from data.Getdata() is not correct. So any idea how will it can be done?
My code:
@Override
protected void onCreate(Bundle savedInstanceState) {
//some lines of code
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivityForResult(intent, 0);}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data)
if (data != null) {
Uri uri_1= data.getData();
String path=uri_1.getPath();;
File custom_file=new File(path);
//searching for specific file type in given folder
ArrayList<File> my_files= fetch_files(custom_file);
//rest of code to what to do with files I received from fetch_files
}