Error saving document in SD

2

I am creating an app and I want to save a report with pdf. From what I have seen the itext library is a good choice. I have the problem when creating the document because it returns an error:

    open failed: EROFS (Read-only file system)

The code I use is:

            Document document = new Document();

            File prueva = new File(getExternalFilesDir(null), "prueva.pdf");
            try {
                PdfWriter.getInstance(document, new FileOutputStream(prueva));
            } catch (DocumentException e) {
                e.printStackTrace();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }


            document.open();

In manifest I have added permissions

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

Any ideas? Thank you very much!

    
asked by Ferran 16.03.2018 в 16:07
source

1 answer

0

Using the aforementioned code on a physical device should not be a problem since the file would be created in the primary (primary) external storage directory since you are using the getExternalFilesDir () .

On the other hand, if you are using an emulator, you must have permissions to write in the system, if you do not have them you can start your emulator in this way:

go to the /sdk/emulator folder where you hold your Android SDK and run it in this way

>emulator -writable-system -avd <Nombre emulador> -no-snapshot-load -qemu

for example if your AVD is called Nexus 5X API 25 you would do it this way:

>emulator -writable-system -avd Nexus_5X_API_25 -no-snapshot-load -qemu
    
answered by 16.03.2018 / 20:12
source