String s = params[0];
// Toast.makeText(activity,s,Toast.LENGTH_SHORT).show();
try {
URL url = new URL(s);
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); //打开连接
int size = conn.getContentLength();//获取文件大小
//0标记表示需要更新最大进度值,1表示更新当前下载的进度取
publishProgress(0,size);
byte[] bytes = new byte[20];
int len = -1;
InputStream inputStream = conn.getInputStream(); //读取数据流
FileOutputStream fileOutputStream = new FileOutputStream("/storage/emulated/0/"+ System.currentTimeMillis()+".jpg");
while ((len=inputStream.read(bytes)) != -1){
fileOutputStream.write(bytes,0,len);
publishProgress(1,len); //更新进度
fileOutputStream.flush();
// Thread.sleep(500);
}
fileOutputStream.close();
inputStream.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
提示以下错误:java.io.FileNotFoundException: /storage/emulated/0/1483081566430.jpg: open failed: EACCES (Permission denied)
本人使用小米5s真机, <uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>权限都添加了。求解