ОТКАЗАНО В ДОСТУПЕ, когда я пытаюсь сохранить телефон из своего приложения на телефон пользователя

У меня есть приложение, в которое пользователь может загружать изображения (я храню их в firebase), и у меня есть кнопка «скачать», когда другой пользователь хочет сохранить это изображение тоже на телефоне.

Я добавляю разрешение в свой манифест:

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

но все же я получаю следующее сообщение:

E/Error:: /storage/emulated/0/test.JPEG (Permission denied)

мой код ниже:

class DownloadFileFromURL extends AsyncTask<String, String, String> {

    /**
     * Downloading file in background thread
     * */
    @Override
    protected String doInBackground(String... f_url) {
        int count;
        try {
            URL url = new URL(f_url[0]);
            URLConnection conection = url.openConnection();
            conection.connect();

            // this will be useful so that you can show a tipical 0-100%
            // progress bar
            int lenghtOfFile = conection.getContentLength();

            // download the file
            InputStream input = new BufferedInputStream(url.openStream(),
                    8192);

            // Output stream
            OutputStream output = new FileOutputStream(Environment
                    .getExternalStorageDirectory().toString()
                    + f_url[1]);

            byte data[] = new byte[1024];

            long total = 0;

            while ((count = input.read(data)) != -1) {
                total += count;
                // writing data to file
                output.write(data, 0, count);
            }

            // flushing output
            output.flush();

            // closing streams
            output.close();
            input.close();

        } catch (Exception e) {
            Log.e("Error: ", e.getMessage());
        }

        return null;
    }

и вот как я это называю

new DownloadFileFromURL().execute(photoUri,"/test.JPEG");

что здесь не так? Есть идеи?


person ChristosV    schedule 05.09.2018    source источник
comment
Вы проверяете, что у вас действительно есть разрешение перед доступом к файлам?   -  person Basil    schedule 05.09.2018
comment
читайте о разрешениях во время выполнения.   -  person Nouman Ch    schedule 05.09.2018