0
I have an application that generates a pdf through a button and when clicking on the button opens a alertdialog where I name my file and therefore opens a snackbar with the title " Do you want to open the file ?" and a "yes" button and when clicking it opens the download directory and not the Documents and when clicking on some PDF it does not open and return to the application. What can it be ?
Follow snippet of the snackbar button:
Snackbar snackbar = Snackbar.make(constraintLayout,"Deseja abrir arquivo :", Snackbar.LENGTH_INDEFINITE);
snackbar.setAction(" ", new View.OnClickListener() {
@Override
public void onClick(View v) {
String pdf = nomepdf.getText().toString();
File file = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS);
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.setDataAndType(Uri.parse(String.valueOf(file+"/"+pdf+".pdf")), "application/pdf");
intent.addCategory(Intent.CATEGORY_OPENABLE);
Intent chooser = Intent.createChooser(intent, "Open File !");
startActivity(chooser);
}
});
You can enrich your answer by explaining what these lines of code are for.
– RXSD
Continued the same way, why will be ?
– IF12
I edited the answer maybe it’ll help
– Caique Oliveira
I think it worked, but when running Intent chooser, I get the message that PD reading applications have been blocked, disabled or not installed. The native android player does not work and the reader I have installed also did not work.
– IF12