当我尝试将手机从应用程序保存到用户手机时,拒绝访问

时间:2018-09-05 06:54:04

标签: android firebase permissions android-external-storage

我有一个应用程序,用户可以上传图像(将它们存储到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");

这是怎么了?有想法吗?

0 个答案:

没有答案