为了账号安全,请及时绑定邮箱和手机立即绑定

Android6.0可以显示图片,10.0提示异常

IOException=java.io.FileNotFoundException: /storage/emulated/0/1583555688940.jpg: open failed: EACCES (Permission denied)

提示没有权限,动态权限也添加了,手动到设置里去打开了存储权限,再进入,依然提示这个异常,模拟器运行,Android6.0显示正常。

正在回答

3 回答

public static Bitmap loadImage(String sendUrl) {
    try {
        URL url = new URL(sendUrl);
        HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
        conn.setReadTimeout(5000);
        conn.setRequestMethod("GET");
        InputStream stream = conn.getInputStream();
        String fileName = System.currentTimeMillis()+".jpg";
        FileOutputStream outputStream = null;
        File fileDownload = null;
        if (Environment.getExternalStorageState().equals(
                Environment.MEDIA_MOUNTED)) {
            File parent = Environment.getExternalStorageDirectory();
            fileDownload = new File(parent, fileName);
            outputStream = new FileOutputStream(fileDownload);
        }
        byte[] bytes = new byte[2 * 1024];
        int lens;
        if (outputStream != null) {
            while ((lens = stream.read(bytes)) != -1) {
                outputStream.write(bytes, 0, lens);
            }
            return BitmapFactory.decodeFile(fileDownload.getAbsolutePath());
        } else {
            return null;
        }
    } catch (MalformedURLException e) {
        //这个URL能不能被解析成URL
        e.printStackTrace();
        Log.e("aa", "异常 MalformedURLException=" + e);
        return null;
    } catch (IOException e) {
        e.printStackTrace();
        Log.e("aa", "异常 IOException=" + e);
        return null;
    }
}


0 回复 有任何疑惑可以回复我~

就是本节所讲的这个例子,下载网络图片,在Android6.0上的模拟器加载的出来,Android10.0的模拟器的提示异常无法显示图片。

0 回复 有任何疑惑可以回复我~

啥意思?


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

Android6.0可以显示图片,10.0提示异常

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信