慕移动7060061
2020-03-07 12:37
IOException=java.io.FileNotFoundException: /storage/emulated/0/1583555688940.jpg: open failed: EACCES (Permission denied)
提示没有权限,动态权限也添加了,手动到设置里去打开了存储权限,再进入,依然提示这个异常,模拟器运行,Android6.0显示正常。
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;
}
}
就是本节所讲的这个例子,下载网络图片,在Android6.0上的模拟器加载的出来,Android10.0的模拟器的提示异常无法显示图片。
啥意思?
Android中的Http通信
10285 学习 · 21 问题
相似问题