I am trying to write a file to the sdcard using the NDK and it always gives me permission denied. Other folks are seeing the same issue and I don't know how to get pass this. Here is the code
void test() {
FILE *file = fopen("/sdcard/test.txt", "w+");
if (nullptr != file) {
fputs("hello, world\n", file);
fclose(file);
} else {
__android_log_print(ANDROID_LOG_VERBOSE, "test", "FAIL with %d", errno);
}
printf("done!");
}
logs:
2023-04-04 17:06:11.755 31824-31824/com.example.readfilenative V/test: FAIL with 13
Manifest:
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:requestLegacyExternalStorage="true"
android:dataExtractionRules="@xml/data_extraction_rules"
gradle
android {
namespace 'com.example.readfilenative'
compileSdk 33
defaultConfig {
applicationId "com.example.readfilenative"
minSdk 24
targetSdk 33
versionCode 1
versionName "1.0"
It is not an option for me to lower to 28, I want to use 33.
I am looking on the this thread:
How to solve OS Error: Permission denied, errno = 13 in flutter
Android studio version
Android Studio Electric Eel | 2022.1.1 Patch 2
Build #AI-221.6008.13.2211.9619390, built on February 16, 2023
Runtime version: 11.0.15+0-b2043.56-9505619 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 11 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 1792M
Cores: 16
Registry:
external.system.auto.import.disabled=true
ide.text.editor.with.preview.show.floating.toolbar=false
cidr.max.intellisense.file.length=1000000
Non-Bundled Plugins:
com.intellij.plugins.visualstudiokeymap (221.6008.15)
GLSL (1.21)
Any clues how to by pass this issue? the permission are definitely enabled on the system UI.
thank you.