Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android saving file to external storage without adding write permission?

Can we write data to external storage without adding write permission in the manifest ? Does Storage access Framework or Download manager gives any support for this?

like image 683
shekar Avatar asked Aug 01 '16 19:08

shekar


3 Answers

It depends where you want to write the files and what SDK(s) you are targeting. If you want to write the files in your app's external directories (getExternalFilesDir(String) and getExternalCacheDir()) and you are targeting SDK19+, then the permission is not required. If you want to write in other areas or targeting SDK<19, then you need the permission. HOWEVER, based on my experience, there is a bug in some Lollipop versions out there that is causing the permission to still be required. So I usually put <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="22"/> in my manifest.

like image 71
N.T. Avatar answered Sep 27 '22 22:09

N.T.


Short answer: no. If there was an easy way to bypass required permissions they'd be pretty pointless. See the documentation below:

https://developer.android.com/training/basics/data-storage/files.html

To write to external storage, you need permission to write to external storage.

Why would you want to take an action you haven't received permission for anyway?

like image 20
EJoshuaS - Stand with Ukraine Avatar answered Sep 27 '22 21:09

EJoshuaS - Stand with Ukraine


Maybe FileProvider is what you are looking for.

FileProvider is part of Support Library, available for all Android versions starting 2.3. The main goal of this API is to temporary open a private file to some targeted apps: you keep the file in your private folder, and let some other apps read or even write it via a secured ContentProvider. Permissions are revoked when your activity is destroyed.

More info

like image 38
Mahdi-Malv Avatar answered Sep 27 '22 23:09

Mahdi-Malv