'Getting Permission Denied when accessing 'storage/0/emulated/download' path even if permissions are granted
I want to download a file to storage/0/emulated/download. It is working fine if we grant permission using Permission.storage.request() at app launch time but if we give permission by clicking on 'Allow' by Permission.storage.request() during run time it gives a permission denied error.
Solution 1:[1]
you should download file to your app OWN(sandbox) storage space
private void saveAppPrivateFils(Bitmap bitmap) {
File file = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), "2.jpg");
BufferedOutputStream bos = null;
try {
bos = new BufferedOutputStream(new FileOutputStream(file));
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, bos);
bos.flush();
bos.close();
Toast.makeText(MainActivity.this, "success", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(MainActivity.this, "fail" + e.toString(), Toast.LENGTH_SHORT).show();
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
