I'm trying to open the download directory in my emulator using Intent.ACTION_GET_CONTENT
.
I can successfully get the path of the downloads directory and list all the files in it, but I can't seem to open it with an intent. It only displays the Recent
directory.
Successfully logs all the files in that download directory, so the path to it is not incorrect
File f = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath());
File[] files = f.listFiles();
if (files != null) {
for (File inFile : files) {
Log.d(TAG, "onPermissionGranted: File name: " + inFile.getName());;
}
}
But when using the intent:
public void openDirectory() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath());
Log.d(TAG, "openDirectory: " + uri);
//logs this: /storage/emulated/0/Download
intent.setDataAndType(uri, "file/*");
startActivity(Intent.createChooser(intent, "Select keystore"));
}
It always displays Recent
Instead of Downloads
I have to manually go to the Downloads
tab
How can I make it so that the intent goes to the Downloads
without having the need to switch?
This is how you do it:
Intent intent=new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS);
startActivity(intent);