Helo, friends i trying to do one image download from the internet using bound services,.through download method i call to bound service class,and through this service one asyctask class is called to display doenload progress through doInBackground(URL... urls) methods. but when output = new FileOutputStream(Path+"hive.jpg");
is called at that time error java.io.FileNotFoundException: /mnt/sdcard/hive.jpg: open failed: EACCES (Permission denied)
occure.please help quickly, thanks in advance.
I taking all the permission that required. my menifist file permission :
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
my backgrounds methods code is following:
@Override
protected Long doInBackground(URL... urls) {
int count;
try {
System.out.println("do in backgrounds");
URL url = new URL(urls[0].toString());
System.out.println("utl=" + url);
URLConnection conexion = url.openConnection();
System.out.println("open connecton+" + conexion);
conexion.connect();
int lenghtOfFile = conexion.getContentLength();
Log.d("ANDRO_ASYNC", "Lenght of file: " + lenghtOfFile);
InputStream input = new BufferedInputStream(url.openStream());
System.out.println("input stream=" + input);
String Path = Environment.getExternalStorageDirectory()
+ File.separator;// "/sdcard/";
System.out.println("PAth=" + Path);
try {
output = new FileOutputStream(Path+"hive.jpg"); // exception error here
System.out.println("output stream=" + output);
} catch (Exception e) {
e.printStackTrace();
}
// OutputStream output = new FileOutputStream(Path+"hive.jpg");
byte data[] = new byte[1024];
long total = 0;
System.out.println("before while");
while ((count = input.read(data)) != -1) {
total += count;
int percent = (int) ((total * 100) / lenghtOfFile);
publishProgress(percent);
output.write(data, 0, count);
System.out.println("file write successfulyy");
}
output.flush();
output.close();
input.close();
System.out.println("close function ");
} catch (Exception e) {
}
//}
return null;
}
Error/Exception are following:
: java.io.FileNotFoundException: /mnt/sdcard/hive.jpg: open failed: EACCES (Permission denied)
at libcore.io.IoBridge.open(IoBridge.java:416)
at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
at java.io.FileOutputStream.<init>(FileOutputStream.java:128)
at java.io.FileOutputStream.<init>(FileOutputStream.java:117)
at com.example.boundservice2.BackgroundDownload.doInBackground(BackgroundDownload.java:63)
at com.example.boundservice2.BackgroundDownload.doInBackground(BackgroundDownload.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
at libcore.io.IoBridge.open(IoBridge.java:400)