Store a File in Android from a JAR File - android

I am writing some backend interface code for an Android App. I would like to package up the backend api in a jar file and include it as a lib in the main app. (I have the same problem even it it's a library project).
One of the features of this api is to download a file from a remote server. I have a method which I pass the "root path" into the api.
public void storeRemoteFile(String rootPath)
The method starts a thread, and in the background grabs the file and stores it to the roothPath. I have no problems running this code in the Console, and the file gets downloaded to my PC. So calling this method in a class that lives in the jar file gives me a file permissions error.
java.io.FileNotFoundException: /storage/adcard0/Android/data/com.myapp/files/temp.zip: open failed: EACCES (Permission denied)
Is there any way to give the api permissions to write the file? If not, are there any suggestions on how to allow the api jar to download the file, and pass it up the main app for storage?

Ensure you have
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
In your Manifest.

Related

react-native-fs ENOENT: open failed: EACCES (Permission denied), open '/storage/emulated/0/Download/ after reinstall

Hello everyone
Environment :
Android 11
react-native 0.68.5
react-native-fs 2.20.0
Need:
Save files persistent to the application (if I uninstall the application the files need to persist). If I reinstall the application I need to be able to manipulate these files again. I uploaded the files in the download folder with RNFS.DownloadDirectoryPath so that they are not deleted when the application is uninstalled but the files are public and can be downloaded to another location if needed.
Error:
Everything works perfectly until I uninstall and reinstall the application. As soon as I want to manipulate an existing file in my /storage/emulated/0/Download/AppName/...
I encounter the following error when I want to move file :
Error: ENOENT: open failed: EACCES (Permission denied), open '/storage/emulated/0/Download/AppName/...
I encounter the following error when I want to download file :
Error: ENOENT: no such file or directory, open '/storage/emulated/0/Download
Before manipulating a file I make sure I have the :
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE
PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE
My build.gradle :
buildToolsVersion = "31.0.0"
minSdkVersion = 30
compileSdkVersion = 31
targetSdkVersion = 31
My manifest :
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
....
android:requestLegacyExternalStorage="true"
android:preserveLegacyExternalStorage="true"
...
A big thank you to the people who will take their time to help me
To try to solve the problem I added this line in my manifest :
android:preserveLegacyExternalStorage="true"
and I changed the minSdkVersion in my build.gradle from 21 to 30.
I have the impression that the rights belonged to the application as if by reinstalling the application it lost its rights.
You did not tell it but this happens to you on Android 11+ devices.
On Android 11+ an app has only access to the files it created itself and media files in public directories.
After reinstall an app is considered a different app.
Use Storage Access Framework ACTION_OPEN_DOCUMENT to let the user pick the files.

Permission denied cordova-plugin-file-opener2

I have downloaded a file, and saved in a directory
cordova.file.externalRootDirectory+'appName/'+file;
and I am using cordova-plugin-file-opener2 plugin to access that file.
But I am getting following error in few phones:
ava.io.FileNotFoundException: /storage/emulated/0/appName/7cc45cf629027499_05750_BG.jpg (Permission denied)
I have checked that file exists at this location.
This depend on the OS, on the new OS version like Nouget you must have read and write permission . Since Android 6.0, the Android permissions checking mechanism has been changed. To make it easier, just use https://github.com/NeoLSN/cordova-plugin-android-permission plugin.
on android I just used the following directory and it worked like a charm:
cordova.file.externalApplicationStorageDirectory
information source
By the way, the FileNotFoundException also occurs when you have permission issues (at least in this plugin).

Android NDK can't open any file

I'm trying to open files from C in my Android app/library. This did work at some point but stopped working after changing several things that seem completely irrelevant, and don't run until after this error occurs.
I am using the following function in C: *ppFile = fopen(fullUncFilePathAndName, "r+b"); and then again with permissions "w+b"
After each of these calls, errno = 13 (Permission Denied).
The file path is /data/data/{appFolder}/files/{filename} (got from Context.getFilesDir().getAbsolutePath(), and the working directory according to the C functions is "/". This is on internal storage, but I added the permission WRITE_EXTERNAL_STORAGE just because I had nothing else to do.
Can anyone think why reading or writing to existing and non-existent files in internal storage from an NDK library would fail with permission errors?
This problem solved itself in the best worst way possible. I deleted my app's data folder in the file browser, and then at the next build the app created its files without a hitch.
You could also clean the project and recompile from scratch.

Issue with application files folder in android

I'm trying to create zip file inside my application files folder (/data/data/myapp/files) but getting "failed to create zip file | open failed: EACCES (Permission denied)" error message every time. As I can see using android debug bridge, my files folder have "rwx------" permissions and "root" owner and group. I think this is the problem but I can't understand why my folder have this owner and group?
Make sure you :
have rooted your device
have the rights to write on the internal storage
are not trying to test it with the usb storage enabled on your phone
added the permission <uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" /> in your manifest
I solved the problem by manually setting right owner, group and permissions on my application files folder (using chmod, chown and chgrp commands). It does not seem like an answer, because it is still unclear why this folder got wrong permissions but unfortunately I don't have enough time to understand where problem is.

Setgid() call return fail in JNI

I am writting jni code for a netTV project apk. so I write code line like setgid(AID_AUDIO) in jni to make the current process have right to write data to the audio devices.
The problem is the setgit(AID_AUDIO) return fail because a common apk program can have user permission. I know that common apk cannot access to any device over jni, but my question is: how can I get my apk have system or root permission?

Categories

Resources