Wednesday, 23 December 2020

Intent ACTION_GET_CONTENT returns uri even for deleted files

I am trying to read pdf files in android app.

Fire following intent to get uri.

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("application/pdf");
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
startActivityForResult(intent, PDF_FILE_SELECTOR_INTENT_ID);

Problem is, the Downloads folder also shows old files which I have deleted. Also, when I select those files a valid uri is returned in onActivityResult(). When I create File from uri and check exists() it returns false which makes sense as I have already deleted the file from the Downloads folder.

How can I make sure that the Downloads folder shown on ACTION_GET_CONTENT shows only files which are currently present and not deleted ones?

Thanks.



from Intent ACTION_GET_CONTENT returns uri even for deleted files

No comments:

Post a Comment