0

after i created pdf, i want to make the app will ask for which app i want to use to open the pdf file in android 11

this is my code

File file = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "/Data.pdf");

try {
pdfDocument.writeTo(new FileOutputStream(file));
Toast.makeText(Cari.this, "PDF sudah dibuat di " + file, Toast.LENGTH_LONG).show();
}
catch (IOException e) {
e.printStackTrace();
}

pdfDocument.close();

Intent myIntent = new Intent(Intent.ACTION_VIEW);
myIntent.setData(Uri.fromFile(file));
Intent j = Intent.createChooser(myIntent, "Choose an application to open with:");
startActivity(j);

the code above will force close the app, how the correct code to open the pdf file in android 11?

Naufal
  • 69
  • 1
  • 8

0 Answers0