I had same problem with Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
. The path which was returned, was something like "/document/primary:Download/a.c" . When I create File object with that path, it was showing exists()
and canRead()
as false
. What I did was, took the path after ":", that is "Download/a.c" and merged that with "/storage/emulated/0/". So final path is "/storage/emulated/0/Download/a.c" . Worked fine with internal storage.
In case of only permission problem make use of this.
ActivityCompat.requestPermissions(MainActivity.this, new String[]{READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE},THIS_REQUEST_CODE);
and override this
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)
{
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}