Android: Copying a file from the assets folder to the phone memory

0

I'm making an application, which on a button that the user presses, will open a PDF file ...

Here's the problem, this file is in the Assets folder and I want to put it in Android's internal memory ...

The problem arrives there, Android 7.0+ is not copying ... My current code:

    private void abrirCalendario() {
        AssetManager am = getAssets();
        AssetFileDescriptor afd = null;
        try {
            afd = am.openFd( "calendario_2017.pdf");

            File file = new File(Environment.getExternalStorageDirectory() + java.io.File.separator + "calendario_2017.pdf");
            file.createNewFile();

            copyFdToFile(afd.getFileDescriptor(), file);

        } catch (IOException e) {
            Toast.makeText(m, "Erro! Libere mais espaço no seu armazenamento!", Toast.LENGTH_SHORT).show();
            e.printStackTrace();
        }

        Intent i = new Intent(Main.this, LeitorPDF.class);
        startActivity(i);
    }
    public static void copyFdToFile(FileDescriptor src, File dst) throws IOException {
        FileChannel inChannel = new FileInputStream(src).getChannel();
        FileChannel outChannel = new FileOutputStream(dst).getChannel();
        try {
            inChannel.transferTo(0, inChannel.size(), outChannel);
        } finally {
            if (inChannel != null)
                inChannel.close();
            if (outChannel != null)
                outChannel.close();
        }
    }

It's there

    
asked by anonymous 28.05.2017 / 19:37

0 answers