Android6.0可以顯示圖片,10.0提示異常
IOException=java.io.FileNotFoundException: /storage/emulated/0/1583555688940.jpg: open failed: EACCES (Permission denied)
提示沒(méi)有權(quán)限,動(dòng)態(tài)權(quán)限也添加了,手動(dòng)到設(shè)置里去打開(kāi)了存儲(chǔ)權(quán)限,再進(jìn)入,依然提示這個(gè)異常,模擬器運(yùn)行,Android6.0顯示正常。
2020-03-10
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)?{ ????????//這個(gè)URL能不能被解析成URL ????????e.printStackTrace(); ????????Log.e("aa",?"異常?MalformedURLException="?+?e); ????????return?null; ????}?catch?(IOException?e)?{ ????????e.printStackTrace(); ????????Log.e("aa",?"異常?IOException="?+?e); ????????return?null; ????} }2020-03-10
就是本節(jié)所講的這個(gè)例子,下載網(wǎng)絡(luò)圖片,在Android6.0上的模擬器加載的出來(lái),Android10.0的模擬器的提示異常無(wú)法顯示圖片。
2020-03-07
啥意思?