I am trying to create few files in Android app-specific folder in external storage. As this is specific to my app only and not required for the user purpose so, its placed at this location.
The API that I am using is getExternalFilesDir. If I try to create the folder using mkdir at this location, it is giving me return value as -1 and errno with the value of PERMISSION_DENIED. As this API doesn't require any permission from the user, we should be able to create files and directory at this place.
This is observed from only Android's API 33 version. Is there anything changed?
Edit:
// This is the Main activity class class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding private lateinit var externalAppSpecificPath : String public external fun CreateDir (pString: String) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) // Example of a call to a native method binding.sampleText.text = stringFromJNI() externalAppSpecificPath = applicationContext.getExternalFilesDir("").toString() Log.d ("TAG", externalAppSpecificPath) // Jumping to C++ CreateDir (externalAppSpecificPath) } /** * A native method that is implemented by the 'testapp' native library, * which is packaged with this application. */ external fun stringFromJNI(): String companion object { // Used to load the 'testapp' library on application startup. init { System.loadLibrary("testapp") } } } // CPP file extern "C" JNIEXPORT void JNICALL Java_com_example_testapp_MainActivity_CreateDir(JNIEnv *env, jobject thiz, jstring p_string) { const char * string = env->GetStringUTFChars(p_string, nullptr); const char * subfolder = "/subfolder"; int newlength = strlen(string) + strlen(subfolder) + 1; char * newstring = new char [newlength]; strcpy(newstring, string); strcat(newstring, subfolder); __android_log_print (ANDROID_LOG_VERBOSE, "Tag", "New string->%s", newstring); int ret_val = mkdir ((const char *) newstring, S_IRWXU); __android_log_print (ANDROID_LOG_DEBUG, "Tag", "mkdir return value-->%d, errno-->%d", ret_val, errno); } 
return value as -1mkdir returns true or false. What would -1 be? You did not tell.