I'm developing an app where I select a .pdf file from the storage, it works when I try it on versions of android 5.1 and 6, but then I try on android 8 and it does not get the file, it does not pop the app just does not show it. How can I make it work on android 8 as in versions 5.1 or 6 ?. The user does grant external storage permits
private void checkStoragePermission() {
if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
selectDocument();
} else {
ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, REQUEST_PERMISSION_STORAGE);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == REQUEST_PERMISSION_STORAGE && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
selectDocument();
} else {
Toast.makeText(getContext(), "Por favor conceda el permiso.", Toast.LENGTH_SHORT).show();
}
}
private void selectDocument() {
Intent intent = new Intent();
intent.setType("application/pdf");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, REQUEST_CODE_DOCUMENT);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_DOCUMENT && resultCode == Activity.RESULT_OK && data != null) {
Uri selectedFileUri = data.getData();
selectedDocumentPath = FilePath.getPath(getContext(),selectedFileUri);
if (selectedDocumentPath != null && !selectedDocumentPath.equals("")){
edtSymptomFile.setText(selectedFileUri.getPath());
}
}
}