0

I'm trying to save this PDf file in external storage but it only works for android 9 and below since something was removed for Android 10+. How can i save the file for android 10+.Kinda new with app dev so didn't understand the documentation.

                myPdfDocument.finishPage(myPage1);

                File file = new File(Environment.getExternalStorageDirectory(),"Client.pdf");

                try {
                    myPdfDocument.writeTo(new FileOutputStream(file));
                } catch (IOException e) {
                    e.printStackTrace();
                }
                finally {
                    Snackbar.make(view, "PDF Created at" + Environment.getExternalStorageDirectory()+"Client.pdf", Snackbar.LENGTH_LONG)
                            .setAction("Action", null).show();
                }
                myPdfDocument.close();

1 Answers1

0
android:requestLegacyExternalStorage="true"

add this in your manifest under application tag.

WRITE_EXTERNAL_STORAGE when targeting Android 10

also read this

Shashank
  • 111
  • 6
  • I guess this will actually work for android 10 currently but won't it get bugged if app is used on android 11 and above devices. I somehow need to make this work on 10+ devices. – The Tech Weaver Feb 09 '21 at 06:15
  • https://developer.android.com/training/data-storage/use-cases#write-files-secondary-storage-volumes – Shashank Feb 09 '21 at 06:25