I uploaded an android photo compress application in play store and I checked every thing is ok, but some users have issue that the application can not save compressed photos, I checked that and I found this error
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: FileSystemException: Cannot create file, path = '/storage/emulated/0/My Folder/photo.jpg' (OS Error: Operation not permitted, errno = 1)
This is permissions AndroidManifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION"/>
<uses-permission android:name="android.permission.CAMERA"/>
This line inside application tag
android:requestLegacyExternalStorage="true"
I looked for some solutions and founded this permission line
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
But when ask for this permission android shows to user warning the application will access to all files without asking permission, I feel this is worrying for users and some may be afraid of this permission, however I uploaded the application but it was rejected because using MANAGE_EXTERNAL_STORAGE permission.
you are right regarding MANAGE_EXTERNAL_STORAGE permission. Your app will be removed from play store if you don't have valid reasons. You may have to create a video and explain why you need these permission, and how scoped storage can't help you.
Now, you should know one thing that you are trying to create a folder directly inside internal storage. This will work in lower android versions but will fail in Android 10 or above even when you have WRITE_EXTERNAL_STORAGE granted.
Try creating your files inside public directories like Download or Documents. If the files downloaded doesn't need to be accessed by users then you can always save in your package folder context.getExternalFilesDir(null)
Hope this helped you! If you have any further doubts feel free to comment down below.
Related
I am using Room DB to save data locally in android.
Now, I want to preserve the data even user uninstall the application or do clear storage.
So, I created Room DB in following location.
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS).getPath()
Everything works fine.
But if I clear the storage or uninstall the application and I open the application again, I am getting following error.
Caused by: java.util.concurrent.ExecutionException: android.database.sqlite.SQLiteCantOpenDatabaseException: Cannot open database '/storage/emulated/0/Download/database/hhcf': File /storage/emulated/0/Download/database/hhcf is not readable
This issue coming in Android 11. For Android 9 no excetion is there.
I have granted following permissions as well.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
And,
android:requestLegacyExternalStorage="true"
in application tag.
Any help would be appreciated.
You need to request user permission to get this permission, adding it only in manifest won't work, at least it didn't for me. I did something like this:
#RequiresApi(api = Build.VERSION_CODES.R)
public void checkFileAccessPermission() {
if (Environment.isExternalStorageManager()) {
return;
}
Intent getPermission = new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
startActivityForResult(getPermission, 123);
}
It's a solution from this thread: How to obtain MANAGE_EXTERNAL_STORAGE permission
But remember that if you want your app to be on the google play store you need to justify to google why you need this permission like this article says: https://support.google.com/googleplay/android-developer/answer/10467955?hl=en
If you use another path for files e.g method getFilesDir() you won't have this problem either, but it's only good if developing a new app, or something like that.
In my Application I'm using expo-image-picker to pick image to update the user's profile picture.
I had done the implementation. while implementing I used CAMERA_ROLL as type to check the permissions for Gallery.
By Default Expo is includes all permissions link. I don't need that. I need to use only CAMER_ROLL as permission. I went through the app.json configuration docs but there, I can't find CAMER_ROLL or GALLERY related permissions.
What permission to be added in app.json for CAMERA_ROLL ?
You need to add these permissions to your AndroidManifest.xml file.
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
I also had similar scenario. CAMERA_ROLL permission is all about reading and writing to the storage memory. So, it requires below Android permission needs to be added in app.json
READ_EXTERNAL_STORAGE
WRITE_EXTERNAL_STORAGE
I'm testing my app on an emulator. I have an export function where I create and write to a file in the external storage's downloads directory. And I also have an import function where I read a file from the external storage's downloads directory.
From Android documentation:
If the device is running Android 5.1 or lower, or your app's target SDK is 22 or lower: If you list a dangerous permission in your manifest, the user has to grant the permission when they install the app; if they do not grant the permission, the system does not install the app at all.
If the device is running Android 6.0 or higher, and your app's target SDK is 23 or higher: The app has to list the permissions in the manifest, and it must request each dangerous permission it needs while the app is running. The user can grant or deny each permission, and the app can continue to run with limited capabilities even if the user denies a permission request.
My emulator is running on Android 6.0 and my app's target SDK is 25, therefore I must also request each dangerous permission it needs while the app is running. I did so for the export functionality and everything works properly. However, when I'm implementing the import function I didn't request a permission during runtime. And the strange thing is I'm still able to read from my external storage's permission without READ_EXTERNAL_STORAGE being requested and granted at runtime. READ_EXTERNAL_STORAGE is a dangerous permission according to this Android documentation .
To verify, I made sure to disable permissions before I started using the feature and after it is completed, I verified again that the permission still wasn't granted. Although I'm happy with the behaviour since it's working without me requesting permission at runtime, but according to the documentations I don't believe this behaviour is expected. That's why I will like to know what's causing this and to figure out the problem before I publish any changes for the app.
Here's a code snippet of my manifest:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
The code snippet where I pick a file to read:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("text/*");
startActivityForResult(intent, GET_FILE_RESULT_CODE);
The code snippet where I read the file chosen from the code snippet above (exportFile is simply the URI from onActivityResult):
BufferedReader br;
try {
br = new BufferedReader(new InputStreamReader(context.getContentResolver().openInputStream(exportFile)));
String line;
// Skip first header line
br.readLine();
while ((line = br.readLine()) != null) {...}
Thanks!
There's a well explanation here,
READ_EXTERNAL_STORAGE
Provides protected read access to external storage. In Android 4.1 by
default all applications still have read access. This will be changed
in a future release to require that applications explicitly request
read access using this permission. If your application already
requests write access, it will automatically get read access as well.
There is a new developer option to turn on read access restriction,
for developers to test their applications against how Android will
behave in the future.
In short, READ_EXTERNAL_STORAGE only exists as of Jelly Bean (Level 16). So, unless you're using a Jelly Bean phone and set the developer option "Protect USB storage" it won't be a problem.
You know,Android Runtime Permissions are grouped, since you applied for WRITE_EXTERNAL_STORAGE permission in the manifest already, so there's no need to apply for READ_EXTERNAL_STORAGE permissions.Both of them are the same group.
In Appcelerator Titanium, I've build a simple one-page app that adds Roman Numerals. As best as I can tell, it has no need to ask for any permissions.
However, my friend testing the app told me it asks for access to the network and in the build/android/ directory the AndroidManifest.xml file includes these lines:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
There's nothing in the tiapp.xml file requesting these permissions and I started with a stock, blank project and don't import any modules or widgets.
Where did these permission requests originate? How do I get rid of them?
All the info I can find discusses how to add or request a permission, but nothing explains how to ensure unnecessary permissions don't show up in the generated AndroidManifest.xml.
It is quite possible that those permissions are defined in one of the Android Libraries used by your app. Android build system provides tools to control how manifest merge is done. Try disabling manifest merge for <uses-permission/> elements of your app's manifest. See Merge Multiple Manifest Files docs.
Have a look at the builder.py (.titanium/mobilesdk/linux/5.3.0.GA/android/builder.py) somewhere around line 982. There you'll find the default permissions for Android. You can try to remove them and see if you have any errors. Make sure to disable the analytics first!
I have created an android application which downloads images from URLs given and download and save it into my sdcard. The image is to be saved into /mnt/sdcard/TempImages folder. and the image is then loaded into imageview for viewing it in my android activity. Till, today morning the application was working very fine, but from today morning onward, when I try to run the application, the image cannot be viewed in my activity. I have been loading the images from my own web server and I have given full permission for read or write access to the files in the server. So there is no problem from the server side. The problem is from the client side. This is the error log while trying to run the application. How should I add permission for my application in the /mnt/sdcard/TempImages folder for read and write access.
W/System.err(458): java.io.FileNotFoundException: /mnt/sdcard/TempImages/-1267781495 (Permission denied)
Make sure your app has the proper permissions to be allowed to write to external storage:
It should look something like this in your manifest file:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
add WRITE_EXTERNAL_STORAGE permission in manifest
Make sure you add the correct permission on your app manifest
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />