Android6.0可以显示图片,10.0提示异常
IOException=java.io.FileNotFoundException: /storage/emulated/0/1583555688940.jpg: open failed: EACCES (Permission denied)
提示没有权限,动态权限也添加了,手动到设置里去打开了存储权限,再进入,依然提示这个异常,模拟器运行,Android6.0显示正常。
IOException=java.io.FileNotFoundException: /storage/emulated/0/1583555688940.jpg: open failed: EACCES (Permission denied)
提示没有权限,动态权限也添加了,手动到设置里去打开了存储权限,再进入,依然提示这个异常,模拟器运行,Android6.0显示正常。
2020-03-07
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;
}
}举报